Calculate the factorial of a number with C.
#include <stdio.h>
int main()
{
int i, num;
long long fact = 1;
printf("Enter any number to calculate factorial: ");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
fact = fact * i;
}
printf("Factorial of %d = %llu", num, fact);
return 0;
}
output:-
Enter any number to calculate factorial : 5
Factorial of 5 = 120
0 Comments