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; }
Output:
Enter a value: 1453Reverse number:3541Sum of Digits:13No Of Digits:4