Program to find factorial of number

0 Suresh Chand June 2, 2021

In this example, We will learn a program to find factorial of number using loop. Before that, You must have knowledge in following topics

Download Application: Learn C Programming with Live Compiler

Algorithm

This is the algorithm of program to find factorial of a number

Step 1: Start

Step 2: Initialize 3 variables fact = 1, i and n

Step 3: Take input from user and assign to variable n

Step 4: Assign i  = 1

Step 5: Repeat this STEP until i <= n

Step 5.1: fact = fact * i

Step 5.2: i++

Step 6: Print fact

Step 7: End

Flowchart

This is the flowchart of program to find factorial of a number

Flowchart : Program to find factorial of number

CODE: Program to find factorial of number

We will find factorial of number using for loop.

#include<stdio.h>

int main(){

    int fact, i, n;
    fact = 1;

    printf("Enter the number : ");
    scanf("%d" , &n);

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

    printf("\nFactorial of %d is %d", n , fact);

    return 0;

}

The output of above program is

Enter the number : 5
Factorial of 5 is 120
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

Ads Block Detector Powered by codehelppro.com

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System