27 December, 2012

C++ Program To Find A Factorial Of A Number.

This Post Contains A C++ Program To Find A Factorial Of A Number With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'For-Loop' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.

# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.


C++ Program To Find A Factorial Of A Number.

/* Declaration Of Header Files */
# include <iostream.h>
# include <conio.h>

/* Start Of Main Program */
void main()

{

   /* Declaration Of Variables */
   int i, Num = 0, f;

   clrscr();

   /* Asking For The Input From User */
   cout << " Enter Any Number : ";

   cin >> Num;

   /* Source Code For Computing Factorial Of A Number */
   f  =  1;

   for ( i  =  Num;  i  >  0;  i-- )

   {

       f  =  f  *  i;

   }

   cout << " Factorial Of  No. " << Num << " : " << f;

   getch();

}
/* End Of Main Program */

Output :

Enter Any Number  :   6!

Factorial Of  No. 6  :   720



No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.