Program in C to print reverse of given number in different ways
For example :
num = 100
rev = 001
1st way
// Programming.OM #include<stdio.h> int main() { int n,r; printf("Enter a number:-"); scanf("%d",&n);printf("Reverse = "); while(n>0) { r=n%10; printf("%d",r); n/=10; } return 0; }
Output:-
2nd way
// Programming.OM #include<stdio.h> int main() { int i,n,r; char rev[10]; printf("Enter a number:-"); scanf("%d",&n); i=0; while(n>0) { r=n%10; rev[i++]=48+r; n/=10; } rev[i]='\0'; printf("Reverse = %s",rev); return 0; }
Output:-
2 Comments