Answer to Question #239090 in C for Doncent

Question #239090

Write a program that prompts the user to input a four-digit positive integer. The program then outputs 

the digits of the number, one digit per line. For example, if the input is 3245, the output is:

3

2

4

5


1
Expert's answer
2021-09-19T08:06:00-0400
#include <stdio.h>
int main()
{
    int num, x, y, z, m = 0;
    printf("Please enter a four digit number: ");
    scanf("%d", &num);
    printf("\n");
    m = num % 10000 / 1000;
    printf("%d",m);
    printf("\n");
    z = num % 1000 / 100;
    printf("%d",z);
    printf("\n");
    y = num % 100 / 10;
    printf("%d",y);
    printf("\n");
    x = num % 10;
    printf("%d",x);
    printf("\n");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS