Since you're getting a negative number this suggests to me that Turbo C is using 16-bit ints and you're getting a signed overflow; i.e. the range of a signed 16-bit integer is −32,768 to 32,767 (assuming 2s complement representation). Therefore if you enter any number > 32767 things are not likely to be what you expect.
Try this on your compiler:
Code:
#include<stdio.h>
int main ()
{
int num, n1,n2,n3,n4,n5,rev;
num =65535;
printf("Number is %d\n",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);
return 0;
}
If Turbo C is indeed using 16-bit ints then you'll get something along the lines of
Code:
Number is -1
Reverse of the number is -10000
I have no idea if Turbo C has limits.h but if it does (it should) check to see what the values of INT_MIN and INT_MAX are.
For example:
Code:
#include <stdio.h>
#include <limits.h>
int main(void)
{
printf("Range is %d to %d\n", INT_MIN, INT_MAX);
return 0;
}