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
what are the various login options used in loadrunner tool to make a application performance testing
How would Nvidia increase the core clock speed anymore?
WHY SHOULD I HIRE YOU
is the meter head is same as back pressure?
Write a regular expression for "Capgemini Services Pvt.Ltd"
is the used fire extinguisher fall under Hazardous waste material?
how to use two diffirent gatway in one system
i want to know about the scope of IT engineers in ONGC
What do you like and dislike about working for this organisation?
1.orders for a computer are summarized by the additional features and are requested as follows; Proportion of order No features 0.3 One feature only 0.5 More than one feature 0.2 find; 1. what is the probability that an order requests at least one feature? 2. what is the probability that an order does not request more than one feature?
What are special features of Silk Test ? In what way it is advanced than QTP?
pls i need a help from you friends, is there anybody who can help me out with the question been ask from the USA embassy. i will be going for interview next month pls help me
y the range of char is between -128 to 127 only????
What is the purpose of dampening roller
WAP in Java to print the format AMIT M I T