Pages

Ads 468x60px

Sunday, July 22, 2012

C++: Factorial iteratively


#include <iostream>

using namespace std;


void main()
{
double num,fact=1;


cout<<"\t\t\t\"ENTER THE NUMBER\"\t\t\t"<<endl;

cout<<"\t\t\t\t";

cin>>num;

if (num>=0)
{

for (num; num>=1; num--)

fact *=num;

cout<<"\t\t\tTHE FACTORIAL IS\n\t\t\t\t"<<fact<<endl;
}

else
cout<<"ENTER THE POSITIVE NUMBER. FACTORIAL OF NEGATINE NUMBER DOES NOT EXIST."<<endl<<endl<<endl;
}

No comments:

Post a Comment