(A Constituent College of Somaiya Vidyavihar University) : Page No PIC Sem I/August-December 2020
(A Constituent College of Somaiya Vidyavihar University) : Page No PIC Sem I/August-December 2020
Grade: AA / AB / BB / BC / CC / CD /DD
http://cse02-iiith.vlabs.ac.in/
http://cse02-iiith.vlabs.ac.in/exp9/simulation/index.html
_____________________________________________________________________
Books/ Journals/ Websites referred:
_____________________________________________________________________
Problem Definition:
The Program prompts user for entering any integer number, finds the factorial of
input number and displays the output on screen. Use a recursive user defined
function to perform the task. A function find_factorial that calls itself in a
recursive manner to find out the factorial of input number.
Flowchart:
Implementation details:
#include <stdio.h>
int find_factorial (int);
int main()
{
int n, factorial;
//prompts user to enter any integer
printf("\n Enter any positive integer: \n");
scanf("%d",&n);
factorial=find_factorial (n);
//print the value of factorial
printf("\n Factorial = %d",factorial);
return 0;
}
//calling recursive user defined function
int find_factorial (int num)
{
if(num == 0)
{
return 1;
}
else
{
return num * find_factorial (num-1);
}
}
Output(s):
(Attach screenshots of the Output of Program Code implemented in Virtual Lab and
Quiz attempted)
Output :-
for n=5
for n=20
Conclusion:
Hence we wrote a program to find factorial of a number using recursion.