C Program To Calculate The Factorial Of A Given Number Using For Loop


Program Code:

#include <stdio.h>
int main() 
{
    int n, i;
    unsigned long long fact = 1;
    printf("Enter an integer: ");
    scanf("%d", &n);
    if (n < 0)
        printf("Error! Factorial of a negative number doesn't exist.");
    else {
        for (i = 1; i <= n; ++i) {
            fact *= i;
        }
        printf("Factorial of %d = %llu", n, fact);
    }
    return 0;
}


To learn more about programming and coding visit our website. PDF study materials also available on our website.

Log on to: www.thecode11.com