0
1.6kviews
What do you mean by Recursion? Write a program to reverse a number using recursion.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 10 M

Year: May 2016

1 Answer
0
17views

Recursion:

In C, it is possible for the functions to call themselves. A function is called 'recursive' if a statement within the body of a function calls the same function. Sometimes called 'circular definition', recursion is thus the process of defining something in terms of itself.

Reverse a given number using Recursion:

#include<stdio.h>
int rev(int n);

main()
{
int rev_num,n;
printf(“Enter a number”);
scanf(“%d”,&n);
rev_num=rev(n);
printf(“\nReverse of entered number is %d”,rev_num);
}

int rev(int n)
{
static int sum=0,rem;
if(n)
{
    rem=n%10;
    sum=sum*10+rem;
    rev(n/10);
}
else
    return sum;
return  sum;
}

Output:
Enter a number: 427
Reverse of entered number is 724
Please log in to add an answer.