In this tutorial learn how you can write a c program to calculate the factorial of a number.
We are using for loop and if statement for this tutorial.
C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.
Here is the code to calculate the factorial of a number in C programming.
#include <stdio.h> //WAP to calculate factorial of a number.
int main()
{
int num, i, fact = 1;
printf("Please enter any integer:");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if (num <= 0)
printf("The factorial not possible");
else
fact = fact * i;
}
printf("The factorial of %d is %d.", num, fact);
return 0;
}
This is how you can calculate the factorial of a number in c programming. Comment below if you like our tutorial.