The factorial of a nonnegative integer n is written n!
(pronounced “n factorial”) and is defined as
follows:
n! = n · (n - 1) · (n - 2) · … · 1 (for values of n greater
than to 1)
and
n! = 1 (for n = 0 or n = 1).
For example, 5! = 5 · 4 · 3 · 2 · 1, which is 120. Use while
structures in each of the following:
a) Write a program that reads a nonnegative integer and
computes and prints its factorial. Use the
following function prototype to calculate factorial:
int myFactorial(int n);
b) Write a program that estimates the value of the
mathematical constant e by using the formula:
Use the following function prototype to calculate e:
double myE( );
Hint: Use an accuracy of 10 terms.
c) Write a program that computes the value of ex by using
the formula
Use the following function prototype to calculate e:
double myEx(int x);

Answer Posted / amal

#include<iostream>
using namespace std;
int main()
{
int x, factorial = 1;
cout << "Enter integer: ";
cin >> x;
if (x > 0)
{
while (x > 0)
{
factorial *= x;
x--; }
}
cout << "Factorial: " << factorial<<endl;
system("PAUSE");
return 0;
}

Is This Answer Correct ?    21 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

the conditional jump instruction in 8086 have a displacement of more than 1 byte.explain how would you tackle a situation in which it is required to branch,on some condition,to a location which is more than 120 bytes away.

1968


Iam preparing for Visakhapatnam Management Trainee 2009 entrance exam.. If anybody have Visakhapatnam Management Trainee Interview questions Pls forward to my mail id srikanth.avanthi@gmail.com .. It is kindly request..

1514


what is the Relationship between quantity of Gas and capacity of AC machine in tonnage.

1759


computer is male or female.....???

1532


Differences between Java and C++? which is faster?

1625






why every computer should have a boot strap routine?

1531


why there is a collision in switch

1500


NIC question paper

2447


how u test the idoc in inbound and outbound?

1653


how to cable size by Amp with example

2291


can i clearly know courses under oracle

1469


what is Networking?

1794


who are egoless programmers?

1484


WHAT IS THE DIff Between candidate key and primary key?

1483


I need to know the process to add 100 tapes in ATL. Ho to inicialize them to the system? How is all the process i need to follow> Thanks

1849