Write a MAIN function and a FUNCTION to compute the sum of the below series.
1 + 2!/4 + 3!/27 + 4!/256 + ...n!/(n^n)
Determine the general term of the series first.
Within the MAIN function:
• In a while(1) loop: (it causes a permanent loop (a loop that executes for ever).
Read a variable EPSILON of type DOUBLE (desired accuracy) from the standard input.
EPSILON is an extremely small positive number which can be anything between
1E-06 (10^(-6)) and 1E-15 (10^(-15)).
• Program should terminate when zero value is entered for the EPSILON.
• EPSILON value will be passed to the FUNCTION as an argument.
Within the FUNCTION:
• . In a do-while loop:
• . Continue adding up the terms until |Sn+1 - Sn| < EPSILON.
• . Sn is the sum of the first n-terms.
• . Sn+1 is the sum of the first (n+1)-terms.
• When the desired accuracy EPSILON is reached print the SUM and the number of TERMS added to the sum.
TEST the program with different EPSILON values between 1E-06 and 1E-15.
void SumSequence(constdouble eps)
{
//use a do-while loop to figure out the sum sequence
//print results
}
int main()
{
while(1)
{
double epsilon = 0.0;
//get epsilon from user
SumSequence(epsilon);
}
return 0;
}
We're not going to do your homework for you. We're happy to help you get started, and if you have some code with problems in, we'll help you work out what they are.
Have a go at it. When you get stuck, and have some specific questions, come back to us.
Yes, I managed to do it in about 15 minutes. However, board policy is not to give away homework solutions. The code I provided should compile as is. You may take that and begin adding to it to solve your problem. If you encounter specific problems as you implement your solution, you should ask about those specific problems.