Q: if a five digit number is input through the keyboard write a program to reverse the number.
# include <stdio.h>
int main()
{
int n,rem,rev;
printf("enter any number : ");
scanf("%d",&n);
while(n!=0) /*condition used until n becomes zero*/
{
rem= n%10; /*to find the last digit of no*/
n=n/10; /*as n is int so n/10 also be int*/
rev=rev*10+rem; /*to find the reverse of the no entered*/
}
printf("reverse of no is %d",rev);
return 0;
}
-----------------------------------------
output:
enter any number : 12345
reverse of no is 54321
Comments
Post a Comment