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

Popular posts from this blog

Write a program to check if a number is prime or not.

Write a program to print the grades to a student.

write a program (keep taking numbers as input from user until user enters an Odd number)