Answer to Question #238823 in C for Woyengimiesindo Ma

Question #238823
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
1
Expert's answer
2021-09-19T10:27:25-0400
#include <stdio.h>




int main(){
    int number;
    printf("Enter a four-digit positive integer: ");
	scanf("%d", &number);
    if(number < 1000 || number > 9999)
    {
        printf("Wrong number.\n");
	}else{
		for(int i=1000;i>=10;i/=10){
			printf("%d\n",(number / i) % 10);
		}
		printf("%d\n", (number % 10));
	}
    scanf("%d", &number);
    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