C Program To Calculate Factorial Of Given Number Using While Loop

C Program To Calculate Factorial Of Given Number Using While Loop

Example

#include<stdio.h>

void main() {
    int number, factorial = 1, temp;

    printf("nnFactorial Program");
    printf("nnEnter The Number: ");
    scanf("%d", &number);
    
    temp = number;
    
    if (number == 0 || number == 1) {
        printf("n Factorial is: 1");
    } else {
        while (number >= 1) {
            factorial = factorial * number;
            number = number - 1;
        }
        printf("n%d Factorial is: %d", temp, factorial);
    }
}

Output:

Factorial Program

Enter The Number: 5
5 Factorial is: 120

Leave a comment