Using while loop, print out each digit of the inputted integer in separate lines, starting from its rightmost digit until the leftmost digit of the number.
Tip #1: Use % 10 to get the rightmost digit. For example, if you do 412 % 10, then the result would be the rightmost digit, which is 2.
Tip #2: On the other hand, use / 10 to remove the rightmost digit. For example, if you do 412 / 10, then the result would be 41.
Tip #3: You'd have to repeat Tip #1 and Tip #2 inside the while() loop for this problem while the inputted integer is not yet 0.
1
Expert's answer
2021-12-15T02:09:13-0500
#include <stdio.h>
int main(void)
{
int number;
printf("Enter positiv integer");
scanf("%d", &number);
while (number)
{
printf("%d \n", number % 10);
number /= 10;
}
return 0;
}
Comments
Leave a comment