UncleCoder.com

UncleCoder.com

Free programming examples and instructions

# C program to find factorial of a number using While loop

## C program for how to find a factorial (1x2.....xn) of a number using while loop

Posted on 23 Aug 2017 Category: C Views: 13103

Edited on 25 Aug 2017

## C program to find factorial of a number using While loop

Let us see how to find the factorial using 'while loop'.

``````#include<stdio.h>
#include <conio.h>
void main()
{
int n,f=1,i=1;
printf("Enter a number: ");
scanf("%d",&n);

while(i<=n)
{
f = f * i;
i++;
}
printf("factorial= %d",f);
getch();

}
``````

First  read  the number to find the factorial of the number from the user. Then using while loop the value of ‘i’ is multiplied with the value of ‘f’. The loop continues till the value of ‘i’ is less than or equal to ‘n’. Finally the factorial value of the given number is printed.

## OUTPUT

Related article

C program to find factorial of a number using for loop

C program to study while loop

C program to study 'do-while' loop

• View all

• View all

• View all