Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

c program to find the factorial of a number

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

    // shows error if the user enters a negative integer
    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;
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #program #find #factorial #number
ADD COMMENT
Topic
Name
7+6 =