0 votes
347 views
in C programming by (98.9k points)
edited
Explain the recursive function. Write a program to find the factorial of a
number using recursive function.

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

A function that calls itself is called as a recursive function and the implementation of a program that uses recursive function is called as recursion.

A recursive function must definitely have a condition that exits from calling the function again. Hence there must be a condition that calls the function itself if that condition is true.

If the condition is false then it will exit from the loop of calling itself again.

The condition could also be implemented vice verse i.e. if the condition is false then the function calls itself else if the condition is true, it will exit from the loop calling itself again

Program ::

Algorithm :
main() function
Step I : START
Step II : PRINT “Enter a number”.
Step III : INPUT a
Step IV : fact = CALL factorial (arguments: a).
Step V : PRINT fact
Step VI : STOP.
factorial (parameters: a)
Step I : START.
Step II : IF a = 1, THEN RETURN (1)
ELSE RETURN ( a * CALL factorial(arguments: a – 1))

#include<stdio.h>
#include<conio.h>
void main()
{
int no,factorial;
int fact (int no);
clrscr();
printf("Enter a number:");
scanf("%d",&no);
factorial=fact(no);
printf("Factorial=%d",factorial);
getch();
}
int fact (int no)
{
if(no==1)
return 1;
else
return (no * fact (no-1));
}

Related questions

0 votes
1 answer 133 views
0 votes
0 answers 65 views
0 votes
1 answer 1.5k views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...