Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Find factorial

#include <stdio.h>
int main() {
    int number, i;
    unsigned long long fact = 1;
    printf("Enter an integer: ");
    scanf("%d", &number);

    // shows error if the user enters a negative integer
    if (number < 0)
        printf("Error! Factorial of a negative number doesn't exist.");
    else {
        for (i = 1; i <= number; ++i) {
            fact *= i;
        }
        printf("Factorial of %d = %llu", number, fact);
    }

    return 0;
}

    Leave a Reply

    Your email address will not be published.

    Need Help?