Unable to get Reverse of 5-digit number as output
Hi,
This is the first time that I'm posting on this forum. I just singed up today. I had done a course on Computer Application Development about 7-8 years ago. I just wanted to brush up on my coding skills. Thus, I started off with C.
As part of getting myself oriented I am doing the basic coding exercises. At this stage I am not supposed to use 'if-else' decision statements or loops.
The Exercise is to "Write a programme to reverse a 5-digit number input by the user." I have typed the following code in Turbo C. However, I'm not getting the expected result...
I know some people might say that Turbo C is dinosaur like. However, I'd like to know why I'm not getting the correct result, even though there are no errors found during compiling. Anyway, if I'm left with no choice, then, I might as well used a better IDE or something... Following is my code. Please help...
Code:
/* Program to reverse a 5-digit number */
#include<stdio.h>
#include<conio.h>
int main ()
{
int num, n1,n2,n3,n4,n5,rev;
clrscr();
printf("\nPlease enter a 5-digit number: ");
scanf("%d",&num);
n1 = num % 10;
num = num / 10;
n2 = num % 10;
num = num / 10;
n3 = num % 10;
num = num / 10;
n4 = num % 10;
num = num / 10;
n5 = num;
rev = n1*10000 + n2 * 1000 + n3 * 100 + n4 * 10 + n5;
printf("\nReverse of the number is %d",rev);
getch();
return 0;
}
I wonder what exactly is the problem... I wonder what it is that is invisible to my eyes....
Thanks in advance.