Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use C++ only Do not use any concepts beyond Chapter 5 of textbook Do not put any

ID: 3871769 • Letter: U

Question

Use C++ only

Do not use any concepts beyond Chapter 5 of textbook

Do not put any arithmetic expressions in cout statements.

Problem 1: Prompt the user to enter a whole number for the power used in the last element of the series (n) and a floating point number for x. The user should be able to enter a positive or negative number for n. When the user enters a positive number for n the series

1 + x + x2 + x3 + x4 .......... + xn
should be calculated and when the user enters a negative number for n the series

1 + 1/x + 1/x2 + 1/ x3 + 1/x4 .......... + 1/xn

should be calculated.

Output the sum of the series.

Do not use the pow function or create your own function for exponentiation.

Explanation / Answer

Its a problem of the most basic geometric series is 1 + x + x2 + x3 + x4 + ... + xn . This is the finite geometric series because it has exactly n + 1 terms. It has a simple formula:

1+x+x2+x3+....+xn=(1-xn+1)/(1-x)

and there is one infinite geometric series,

which is to be written as 1 + 1/x + 1/x2 + 1/ x3 + 1/x4 .......... + 1/xn. to calculated its and we need have a formula as below.

1 + 1/x + 1/x2 + 1/ x3 + 1/x4 .......... + 1/xn=1/(1-x)

i have written a program to calculate id by using above formula.

Code:

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{

int n;

float x;

float result;

cout<<"Enter the values of n ";

cin>>n;

cout<<"enter the value of x ";

cin>>x;

if(n>0)

{

result=(1-pow(x,n+1));

result=result/(1-x);

}

else

{

result=(1/(1-x));

}

cout<<result;

getch();

}

Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote