0
1.6kviews
Write a recursive program to calculate factorial of accepted number.
1 Answer
written 8.3 years ago by |
Algorithm:
Main () Function:
Factorial (parameters : a)
Program:
#include <stdio.h>
#include <conio.h>
int main() {
int no, factorial;
int fact(int no);
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));
}
Output:
Enter a Number: 5
Factorial = 120