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

how to generate linked implementation of sparse matrix?

1493


15. What is your Future Plans for the Company if Permanently Employed?

3368


Why do you want to work here

1339


what is difference between class and object in c++

1579


what is static identifier in c language?

1698






When to use Stub and Not So Stubby Area? 10. How to get the external routes without making area Not So Stubby?

992


Anyone have thesis paper about "Electrical Load Forecasting" . Or the web addresses where people usually upload their thesis paper except IEEE.

1388


What a test plan contains

1545


Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

1515


i can access command prompt in my pc. when i type cmd in run,message comes-you are restricted.contact admin. why is it so? how can acces it by just logging in as a user and not as admin.?????

1541


what are differences between composition and inheritance in c

1054


How does Earthquake-proofing work?

634


hi friends i am first time using this site.i came to by some tcs personals that certifications r important for placements.i am financially average i am learning java from books.please tell is it enough if not which certification should i go for

1335


what is the definition(body) of a default constructor in c++?

1463


why this for loop doesn't work . int i; for(i=2;i=0;i--) { cout<

1446