Answer to Question #238703 in C for Woyengimiesindo Ma

Question #238703
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-17T16:29:24-0400
#include <stdio.h>

int main()
{
    int number;
    
    printf("Input a four-digit positive integer: ");
    if(scanf("%d", &number) != 1 || number < 1000 || number > 9999)
    {
        printf("Bad input\n");
        return 1;
    }

    printf("%d\n", (number / 1000) % 10);
    printf("%d\n", (number / 100) % 10);
    printf("%d\n", (number / 10) % 10);
    printf("%d\n", number % 10);
    
    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