Write a C program which will take an integer number from keyboard and display its digits on separate lines on monintor using a loop
#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]);
}
Comments
Leave a comment