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 |
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.)
I DO HAVE APAST EXPERIENCE IN MY(SCHOOL/COLLEGE)WHERE I'VE HANDLED RESPONSIBILITY LIKE
how to use two diffirent gatway in one system
Friends Any one tell me the best institute for the telecom protocol course
what is e-bum.
What is necking in production engineering ?
What is success factors online trainings?
what is the cycle between AHU and Chiller
how many E1's in pasolink and ipasolink?
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..
I am an Electrical engineering ( electrical back round ) ,can i get hvac Water system design details to easy understand ,i am working past 15years in Pharmaceuticals company with Engineering depart.
0 Answers Archimedis Healthcare,
How do aeroplanes fly? Why can some fly up-side down?