Write a program to print the reverse of an integer number. Number entered by user using recursion.
In this post we shall learn how to revers a number using recursion in c programming.In this we shall write a program that take an input integer value from user and display the reverse of the entered number.
Example:
user entered number = 123456
output of program = 654321.
Now see the program:
#include<stdio.h>
#include<conio.h>
int reversenumber(int);
int main()
{
int number,result;
printf("Enter Number\t");
scanf("%d",&number);
result = reversenumber(number);
printf("The reverse of number %d is = %d",number,result);
}
int reversenumber(int n)
{
int x;
static int r = 0;
if(n == 0)
{
return(n);
}
else
{
x = n%10;
r = r*10 + x;
reversenumber(n/10);
}
return(r);
}
Output:
Enter Number 456123The reverse of number 456123 is = 321654.
Do not forget to subscribe me for latest update on my blog , follow me and grow your knowledge. thank you
0 comments:
Post a Comment