Search Your Query

Breaking

Saturday, March 30, 2019

Factorial of n Number


Factorial of n Number

Program Code :

#include<stdio.h>
int main(){
int i,a=1,n;
printf("enter the number of n\n");
scanf("%d",&n);
for(i=2;i<=n;i++){
a=a*i;
}
printf("The result is -->%d",a);
return 0;

}

Hence : 
1st loop , when a=1 and i=2 then a=1×2=2
2nd loop , now a=2 and i=3 then a=2×3=6
3rd loop , now a=6 and i=4 then a=4×6=24
4th loop , now a=24 and i=5 then a=24×5=120
Here loop will be stop cause i<=n

Input :

Enter the number of n
5

Output :

The result is --> 120

1 comment: