Search This Blog

Thursday, March 12, 2015

C Program to Reverse a four digit number| C Programming

C Program to Reverse a four digit number| C Programming, C Programs

#include<stdio.h>
int main()
{
int N, a,b,c,d,e;
printf("Enter the  four digit number:");
scanf("%d",&N);
a=N%10;
b=((N-a)%100)/10;
c=((N-a-b*10)%1000)/100;
d=N/1000;
e=a*1000+b*100+c*10+d;
printf("\nThe reversed number is: %d",e);
return 0;
}

Output:
Enter the four digit number:1234
a=4
b=3
c=2
d=1
e=4321
The reversed number is :4321

No comments:

Post a Comment