Factorial of a Number in C

This program calculates the factorial of a given positive integer.

#include <stdio.h>

 int main() {
    int n, i;
    unsigned long long factorial = 1;
    printf("Enter a positive integer: ");
    scanf("%d", &n);
 
    for(i = 1; i <= n; ++i) {
        factorial *= i;
    }
 
    printf("Factorial of %d = %llu\n", n, factorial);
    return 0;
}

No comments:

Post a Comment

MS Excel Logical Functions

Logical functions in Excel are powerful tools that help you make decisions based on conditions. Whether you're comparing values or testi...

Post Count

Loading...