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
Write steps of retrieving data using ado.net?
real time examples for basic concepts in oop
What is spooling and buffering?
how to connect oracle with java ? Give detail explanation.
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.
What is the actual procedure of charging synthetic oil if the machine is under positive refrigerant pressure.
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.)
How many of 14 digit numbers we can make with 1,2,3,4,5 that are divisible by 4. Repetitions allowed.
why u r shifting from engineering to other field ?
can i get some win vista notes
what books to prepare for atc please
sir now i am studying B.Tech final year so now i am eligible for writing group 1 and 2 or not?
can any give an exact example about, resolving the sql errorcode -305
Is there aptitute question will be asked in NIC exam ??? If yes how many questions will be asked??
is the used fire extinguisher fall under Hazardous waste material?