MeshWorld India LogoMeshWorld.
ProgramC1 min read

Calculate Factorial in C Using a For Loop

Listen to ArticleAI Speech
~1 min read narration
100%
Calculate Factorial in C Using a For Loop

A program to find factorial for integer data-type using for loop in C - language

Algorithm for Factorial

Step 1: Start
Step 2: Read a number n
Step 3: Initialize variables: i = 1, result = 1
Step 4: if i <= n go to Step 4 otherwise go to Step 7
Step 5: Calculate result = result * i
Step 6: Increment the i by 1 (i = i + 1) and go to Step 3
Step 7: Display result
Step 8: Stop


Working example

/**
 * Factorial for N using FOR loop
 */
#include <stdio.h>
int main()
{
    int i, n, result = 1;
    printf(" Enter number: ");
    scanf("%d", &n);

    for (i = 1; i <= n; i += 1)
    {
        // printf("\n I : %d", i);
        // printf("\n Result B4 : %d", result);
        result *= i;
        // printf("\n Result After : %d", result);
    }
    printf("\n Factorial of %d : %d", n, result);
    printf("\n");
    return 0;
}

Output for number 5

Enter number: 5

Factorial of 5 : 120

Output for number 6

Enter number: 6

Factorial of 5 : 720

Happy 😄 coding

Reader Quality Feedback

Did this technical guide help solve your problem?

Suggest Errata ($0)
Vishnu
Primary Author

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Explore Author Archive
Compute Fuel & Open Testbed
100% Independent & Verified

Fuel High-Density, Zero-Fluff Engineering Deep-Dives

Every guide on MeshWorld is validated on physical Linux nodes and reproducible testbeds. If this article saved you hours of debugging or unblocked production, consider funding our next cluster run.

Weekly Dispatch

Join MeshWorld Dispatch

Get practical tutorials, system blueprints, and curated AI engineering notes straight to your inbox. No fluff, zero spam.

Zero spam. 1-click unsubscribe anytime.Prefer RSS?
Curated Continuations

Up Next in This Domain.

Browse Full Archive