Saturday, January 29, 2011

A simple Factorial program in c++

What a factorial is ??
A factorial of a number is the multiplication of all the numbers between that number and 1.
Finding factorial of a number is too easy if you simply got the logic discussed above,

Following is a program for finding the factorial of a number

// single line comments start with // lines
/* while multi-line comments start with /* and
end with */

******************* Start of Program ************************

#include"conio.h"
#include"iostream.h"

void main()
{
clrscr(); // to clear the screen
int n,fact=1;

cout<<"Please enter a number to find factorial :: ";
cin>>n;

for(int i=n;i>=1;i--)
{
fact=fact*i;
}


cout<<"Factorial of "<
getch();
}

*********************** END ************************