I want to get the reverse of the 5 digit number but i'm not getting it. I don't know where is the problem.I'm a beginer.In my book book there is a similar kind of problem where it's mentioned that the input value should be less than 32767.my question is why? and the second thing is if i choose any number less than 32767, still i'm not geting the answer.Do I have to choose a value where the reverse number is also less than 32767.please tell me.

#include<stdio.h>
#include<conio.h>

int main()
{
int num,a,b;
int total=0;

printf("Enter a 5 digit number: ");
scanf("%d",&num);
a=num%10;
b=num/10;
total=total+a*10000;

a=b%10;
b=b/10;
total=total+a*1000;

a=b%10;
b=b/10;
total=total+a*100;

a=b%10;
b=b/10;
total=total+a*10;

a=b%10;
total=total+a;

printf("The desired value is:%d",total);

getch();
return 0;
}

In my book book there is a similar kind of problem where it's mentioned that the input value should be less than 32767.

The range of signed int is only assured to be at least[-32,767..+32,767]. If you want your code to be maximally portable, do not assume anything outside that range, or use signed long instead, where the range is assured to be at least [-2,147,483,647..+2,147,483,647].

and the second thing is if i choose any number less than 32767, still i'm not geting the answer.

I get the right answer when I run this program, but the last printf() does not print a line break character, so my guess would be that this is your problem. If you do not print a line break, the output stream might not be flushed before the call to getch(), and you will not see the output. Replace that printf() call with this one and see if it fixes the problem:

printf("The desired value is:%d\n", total);

in C prog all data type is in circle form means range of c is -32768 to +32767
if you try following code you will get -32768
void main()
int no=32768;
printf("%d",no);
}
o/p -32768
if no=32769 o/p will be 32767
if no =32770 o/p wiil be 32766

this beacause if you go beyond range it goes to negative side if you put 65536 you will get 0

void main()
{long int r,rev=0;
long int=9983;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;

}
printf("%ld",rev);
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.