write a program to print the factorial of a number n.
//program to print the factorial of a number n.
// 1!=1
// 2!=1*2=2
// 3!=1*2*3=6
// 4!=1*2*3*4=24
// 5!=1*2*3*4*5=120
#include<stdio.h>
int main()
{
int n, fact = 1;
printf("enter any number=");
scanf("%d", &n);
for(int i=1; i<=n; i++){
fact = fact *i;
}
printf("factorial = %d", fact);
return 0;
}
output :
enter any number=10
factorial = 3628800
--------------------------------
Process exited after 5.793 seconds with return value 0
Press any key to continue . . .
Comments
Post a Comment
Please do not enter any spam link in the comment box.