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

Write steps of retrieving data using ado.net?

1856


real time examples for basic concepts in oop

1203


What is spooling and buffering?

1289


how to connect oracle with java ? Give detail explanation.

1539


could i know the selection pattern at hpcl, am an undergradute in chemical technology, but my sujects or course do not figure out antwhere on the lists.

1505






What is the actual procedure of charging synthetic oil if the machine is under positive refrigerant pressure.

1281


hi all I got two exam call letter one from maha ganeco & other from federal bank both at same time & same date which should i choose (note I am eng. grad.)

1693


How many of 14 digit numbers we can make with 1,2,3,4,5 that are divisible by 4. Repetitions allowed.

1845


why u r shifting from engineering to other field ?

1727


can i get some win vista notes

1291


what books to prepare for atc please

1528


sir now i am studying B.Tech final year so now i am eligible for writing group 1 and 2 or not?

1244


can any give an exact example about, resolving the sql errorcode -305

1466


Is there aptitute question will be asked in NIC exam ??? If yes how many questions will be asked??

1871


is the used fire extinguisher fall under Hazardous waste material?

1439