Write a C Program to Calculate Factorial of a Number

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.


write c program to calculate factorial of a number


Write a Program to Calculate Factorial of a Number

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;
}

Test Live At Jdoodle



Conclusion

This is how you can calculate the factorial of a number in c programming. Comment below if you like our tutorial.

0 Comments