reverse number program in c language
This program reverses a given input number from the user and then print it on the screen. Along with reverse number, we are finding the sum of digits and number of digits also.
#include <stdio.h>
int main()
{
int n,rn,sd,nd;
printf("Enter a value: ");
scanf("%d",&n);
rn=sd=nd=0;
while(n>0) //+ve //while(n<0)-ve //while(n!=0)
{
rn=rn*10+n%10;
sd=sd+n%10;
nd=nd+1;
n=n/10;
}
printf("\nReverse number:%d",rn);
printf("\nSum of Digits:%d",sd);
printf("\nNo Of Digits:%d",nd);
return 0;
}
[quote]
Output:
Enter a value: 1453
Reverse number:3541
Sum of Digits:13
No Of Digits:4
[/quote]