**Question**

**Write a C++ program that calculates the factorial of a number using a function. The Program should use a While Loop. The program prompts the user to enter an integer from the standard input, calculates and displays the factorial of the inputed number. Draw the Flowchart**

**Answer**

The factorial of a number is obtained by continuously multiplying the number with lower integers in steps of 1.

Fatorial of n is given by

Factorial n = n * (n-1) * (n-2) *… * 2 * 1

Factorial 5 = 5 *4 * 3 * 2 * 1 = 120

Flowchart is given below

For the decision, the control continues downwards for NO and branches to the right for YES

C++ Program is given below

//Functions computes the factorial of a number

//By Kindson Munonye

//Date: February 2013

//Date Modified: February 2013

//Location: Port Harcourt, Nigeria

#include ;

#include ;

using namespace std;

int factorial(int n)

{

int fact = 1;

while(n<1) {

fact = fact * n;

n--;

}

return fact;

}

int main()

{

int num;

cout<<"Enter an integer: "; cin>>num;

cout<<"\n\n Factorial "<<num<<" = "<<factorial(num)<<endl;

system("pause");

return 0;

}

//By Kindson Munonye

//Date: February 2013

//Date Modified: February 2013

//Location: Port Harcourt, Nigeria

#include ;

#include ;

using namespace std;

int factorial(int n)

{

int fact = 1;

while(n<1) {

fact = fact * n;

n--;

}

return fact;

}

int main()

{

int num;

cout<<"Enter an integer: "; cin>>num;

cout<<"\n\n Factorial "<<num<<" = "<<factorial(num)<<endl;

system("pause");

return 0;

}

Hello there, I found your blog via Google even as

looking for a related matter, your web site came up, it seems to be good.

I’ve bookmarked it in my google bookmarks.

Hi there, simply turned into alert to your weblog through

Google, and found that it’s really informative. I’m going to watch out for

brussels. I’ll appreciate for those who continue this in future.

Many other folks might be benefited from your writing. Cheers!

Hey very nice blog!! Guy .. Beautiful .. Wonderful ..

I’ll bookmark your site and take the feeds also? I’m glad to search out

numerous helpful information here in the submit, we

want develop more techniques on this regard, thanks for

sharing. . . . . .

These are really wonderful ideas in regarding blogging.

You have touched some pleasant things here. Any way keep up wrinting.

You come across pretty well-written. Would it be

ok to pose some questions?