I am looking for the C
program for reverse the digits like below:
If i enter:
123456
Then the result would
Looks like a very old thread. But I referred the solutions here and had to cook up my own solution after testing the different programs available as solution on this website. I realized that treating the number as int will not yield necessary reversing of digit if the number ends with zero(s). So I decided to treat the number as a string and then reverse the digits. This way, I get exact reverse of the digit from a string standpoint and not a mathematical one that discards zeros at the beginning of a number.
#include
#include
main()
{
char num[20];
int x=0,slen;
printf("Enter the number you want to reverse :");
scanf("%s",num);
slen=strlen(num);
char *pointertoarray = &num[slen];
for (x=slen;x>=0; x--){ printf("%c",*pointertoarray); pointertoarray--; }
printf("\n");
}