Hello,
I am asking the user for an integer and then I need to print out the number that the user entered backwards. I am having a hard time doing this! I know how this achieved, you just take the "x%10"(mod) of the number and print after each time until the number reaches zero.
for example: user enters: 1557
1557%10= 7 ->print
155%10= 5 -> print
15%10= 5 ->print
1%10=1 ->print for the last time b/c after getting 1 then next mod is zero.
My program is incorrect and I know what I am doing wrong, but I dont know how to create the right code, can someone please help?
Code:
#include <stdio.h>
int main() {
int num, i;
printf("Enter a positive integer.\n");
scanf("%d", &num);
while (num > 0) {
num=(num%10);
printf("%d", num);
num--;
}
system("PAUSE");
return 0;
}