Answer to Question #319673 in C for Sami

Question #319673

Write a C program which will take an integer number from keyboard and display its digits on separate lines on monintor using a loop


1
Expert's answer
2022-03-31T05:55:51-0400
#include <stdio.h>

int main()
{
    int number, n;
    int digits [10];
    printf("Enter number: ");
    scanf("%d", &number);
    n = 0;
    while (number != 0)
    {
        digits[n] = number % 10;
        number = (int)(number / 10);
        n++;    
    }
    for (int i=(n-1); i>=0; i--)
        printf("%d\n", digits[i]);
}

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