print 1 to n numbers of Factorial in C
Code is Written and Implemented by : -
HIMANSHU TIWARI
//write a program to print 1 to n numbers of factorials.
#include<stdio.h>
int fact(int n){
if(n==0 || n==1){
return 1;
}else{
return n*fact(n-1);
}
}
int howfact(int n){
for(int i=1; i<=n; i++){
printf("%d = %d \n",i,fact(i));
}
return 0;
}
int main(){
int n;
printf("enter the value : ");
scanf("%d",&n);
howfact(n);
return 0;
}
output :
//enter the value : 5
1=1
2=2
3=6
4=24
5=120
.png)
.png)
Comments
Post a Comment