C Language program to print factorial of given number

Views: 112   

Following program shows you how to print factorial of given number.
In this program we get input from user and prints factorial of that number using for loop

#include <stdio.h>
int main() {
    int input;
    printf("Enter a number:");
    scanf("%d", &input);
    int result = 1;
    for (int i = 1; i <= input; i++)
        result = result * i;
    printf("%d factorial is: %d", input, result);
}

Output:

Enter a number: 6
6 factorial is: 720
On By