Question

Calculate factorial of a Number (e.g., 5!) using for loop in C language

Updated on May 31, 2025 | By Learnzy Admin | πŸ‘οΈ Views: 308 students

Solution
βœ” Verified

This C program calculates the factorial of a given number using a for loop.

The factorial of a number (denoted as n!) is the product of all positive integers from 1 to n. For example, the factorial of 5 (written as 5!) is 5 Γ— 4 Γ— 3 Γ— 2 Γ— 1 = 120.

In this program, the user provides a number, and the for loop multiplies each integer from 1 to that number, storing the result in a variable. This method demonstrates how to use loops for repetitive multiplication and is a classic example used to understand loop-based logic in C programming.

#include <stdio.h>

int main() {
    int num = 5;
    int fact = 1;

    for (int i = 1; i <= num; i++) {
        fact *= i;
    }

    printf("Factorial of %d is %d\n", num, fact);
    return 0;
}

Output:-

Factorial of 5 is 120

Β 

Was this solution helpful? 43
Click here to download practice questions on For Loop In C

More Questions on For Loop In C

Question 1

Print the Alphabet (A to Z) using for loop in C Language


View solution
Question 2

Print a Pattern (Right-Angled Triangle) using for loop in C Language


View solution
Question 3

Calculate sum of First 10 Natural Numbers using for loop in C Language.


View solution
Question 4

Print Table of 5 using for loop in C Language.


View solution
Question 5

Print Even Numbers from 2 to 20 using for loop in C Language.


View solution
Question 6

Print Numbers from 1 to 10 using for loop in C Language.


View solution