Tuesday, 9 June 2015

Program that reads a number ,coumputes and displays its factorial using do-while loop



Code for Program that reads a number ,coumputes and displays its factorial using do-while loop in C++ Programming



 



 
 #include<iostream.h>
 #include<conio.h>

 /*************************************************************************//*************************************************************************///-----------------------------  Main( )  -------------------------------///*************************************************************************//*************************************************************************/

 main()
    {
       clrscr();

       int count=1;
       int number;
       long factorial=1;

       cout<<"\n Enter the number = ";
       cin>>number;

       if(number==0)
      factorial=1;

       else
      {
         do
        {
           factorial=factorial*count;
           count++;
        }
         while(count<=number);
      }

       cout<<"\n factorial ("<<number<<") = "<<factorial<<endl;

       getch();
       return 0;
    }

No comments:

Post a Comment