How to Find Factorial of a Number in C++

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;
}

Output of the Program

Find Factorial of a Number in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment