What is Factorial ?
Factorial of a no. means multiplying below numbers. Factorial is denoted by ! Exclamation mark
Eg:- 5! means :- 5 * 4 * 3 * 2 * 1 = 120
What is a Recursive function?
Definition:- A function which calls itself is called as Recursive function & technique is called as Recursion
Program for factorial of a number using recursive function in C
#include<stdio.h>
#include<conio.h>
int fn(int n);
void main()
{
int num, f;
clrscr();
// Enter the number for factorial
printf(\n Enter the number:-);
scanf(%d, num);
f=fn(num);
printf(\n The Factorial number:-%d,f);
getch();
}
int fn(int n)
{
int y;
if ((n==0)||(n==1))
y=1;
else
y=n*fn(n-1);
return(y);
}
Output:-
Enter the number:- 5
The Factorial number:- 120
0 Comment(s)