C program to find the reverse of a number
#include<stdio.h>
#include<conio.h>
main()
{
int n, r;
printf("Enter The Number:\n");
scanf("%d",&n);
for(r=0; n>0; n=m/10)
{
r=r*10;
r=r+(n%10);
}
printf("The Reverse Number is:\n %d",r);
getch();
}
Output of Program:
C Program to Reverse The Number |
C Program to Reverse the number using recursion
#include <stdio.h>
long reverse(long);
int main()
{
long n, r;
scanf("%ld", &n);
r = reverse(n);
printf("%ld\n", r);
return 0;
}
long reverse(long n)
{
static long r = 0;
if (n == 0)
return 0;
r = r * 10;
r = r + n % 10;
reverse(n/10);
return r;
}
Output of Program:
Reverse Number Using Recursion |
1 Comments
Good..
ReplyDelete