This is the simple and logic building program in C++ for beginners. The program will find the factorial of a given number.
Source Code
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"\a\n\n\n"
<<"\t******************************************************"<<endl
<<"\t** **"<<endl
<<"\t** Welcome To **"<<endl
<<"\t** **"<<endl
<<"\t** Factorial **"<<endl
<<"\t** **"<<endl
<<"\t** Demo **"<<endl
<<"\t** **"<<endl
<<"\t******************************************************"<<endl
<<endl
<<endl;
cout<<"";
int yourNember, incrementor, factorial = 1;
cout<<"Enter your number "<<endl;
cin>>yourNember;
if ( yourNember < 0 )
cout<<"-Negative Number Error"<<endl;
else
{
for ( incrementor = 1 ; incrementor <= yourNember ; incrementor++ )
factorial = factorial*incrementor;
cout<<"Factorial of "<<yourNember<<" is = "<<factorial<<endl;
}
cout <<endl;
system("pause");
return 0;
}
0 comments:
Post a Comment