Answer to Question #242127 in C for Sam

Question #242127

Write a program that prompt the user to input a four digit positive interger. The program then output the digit of the number, one digit per line. For example, if the input is 3245, the is

3

2

4

5

Thanks...


1
Expert's answer
2021-09-25T10:03:26-0400
#include <stdio.h>


int main()
{
    int n;
    printf("\nEnter an integer: ");
    scanf("%d",&n);
    //int n=3245;
    int x1=n/1000;
    printf("%d\n",x1);
    n=n-(x1*1000);
    int x2=n/100;
    printf("%d\n",x2);
    n=n-(x2*100);
    int x3=n/10;
    printf("%d\n",x3);
    n=n-(x3*10);
    printf("%d\n",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
APPROVED BY CLIENTS