Program to find Factorial by using While loop.

Factorial number: The factorial of any number ( let n) indicates the multiplication of series of positive integers starting from n and descending till 1.

 

Let’s open turbo c/c++ and write the following code:

 

 

//Code:

 

 


#include<iostream.h>

#include<conio.h>

void main()

{

long int    i=1,n,fact=1;

clrscr();

cout<<”enter any number:”;

cin>>n;

while(i<n)

{

fact=fact*i;

i++;

}

cout<<”factorial is:”<<fact;

getch();

}

 

 

 

Now, Run the program and see output:

 

 

 

Output:

 

 

output

 

 

Happy coding.

 

 

Tags: , ,

Comments are closed.