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
the conditional jump instruction in 8086 have a displacement of more than 1 byte.explain how would you tackle a situation in which it is required to branch,on some condition,to a location which is more than 120 bytes away.
Iam preparing for Visakhapatnam Management Trainee 2009 entrance exam.. If anybody have Visakhapatnam Management Trainee Interview questions Pls forward to my mail id srikanth.avanthi@gmail.com .. It is kindly request..
what is the Relationship between quantity of Gas and capacity of AC machine in tonnage.
computer is male or female.....???
Differences between Java and C++? which is faster?
why every computer should have a boot strap routine?
why there is a collision in switch
NIC question paper
how u test the idoc in inbound and outbound?
how to cable size by Amp with example
can i clearly know courses under oracle
what is Networking?
who are egoless programmers?
WHAT IS THE DIff Between candidate key and primary key?
I need to know the process to add 100 tapes in ATL. Ho to inicialize them to the system? How is all the process i need to follow> Thanks