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);
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / wew
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);
Is This Answer Correct ? | 14 Yes | 16 No |
which is best car to buy in india, if the budget is below or equal to 3.5 lakhs?
the ability for the processor to delegate its use by application is called
i want a program in c# for 100 or for a number greater than 100.....pls help
why there is a collision in switch
1.what a diffrenrs v-lan & (layer)l-3,l-2 bitween plz define defination of these? 2.how to configur ms outlook & lotus note (ibm)
how 2 write a program of this pattern usin for loop?? 1 2 3 4 5 6 7 8 9 10
if your monitor is not started with your cpu, but start when monitor attach to another cpu then where is the problem?
When are the SBI clerk 2010 results are expected???
Define configuration and calibration and explain with an example
How can I get know that my pc contains dram or sram..?
a particle moving in a straight line with constant acceleration has a velocity of 8m/s at one instant and 3 seconds later it has a velocity of 2m/s.find its acceleration.
Can anyone send me iocl written test paper fro computer engineers