All major conceptual S2 C-Programs with Algorithms
#include <stdio.h>
//define recursive function fact
int fact(int n){
if(n==0||n==1){
return 1; // returns 1 since 0! and 1! is 1
} else{
return n*fact(n-1); // logic > n = 3, 3 * fact(2)=> 3 * 2 * fact(1) = 6
}
}
void main(){
int n;
printf("enter a number");
scanf("%d",&n);
printf("Factorial of %d is : %d",n,fact(n));// calling the function in the main
}