Q. Write a C program to create a function that would reverse the any number.
For example:
Assume enter number = 57429
Result = 92475
Ans:
#include<stdio.h>
int rev(int );
int main()
{
int num,res; // res = result
printf("Enter any number : ");
scanf("%d", &num);
res = rev(num);
printf("Reverse order number = %d",res);
return 0;
}
int rev(int n)
{
int r=0;
for(; n>=1; n=n/10)
r = r*10 + n%10;
return r;
}
Output
No comments:
Post a Comment