Factorial of Any number by using do-while .

Factorial: Factorial are just products,indicated by an exclamation mark. In general “n!” means the product of all the whole numbers from 1 to n; i.e n!= 1x2x3x4x……xn.

 

 

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

 

 

// code

 

 

#include<iostream.h>

#inlude<conio.h>

void main()

{

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

    clrscr();

    cout<<”enter any number:”;

    cin>>n;

    do

{

    fact=fact*i;

    i++;

}

    while(i<=n)

{

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

}

    getch();

}

 

 

 

 

Now run the program and see Output:

 

 

 

output:

 

 

output

 

 

happy coding.

 

 

 

Tags: , , , ,

Comments are closed.