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

C++ programming hw help The infinite series: s = 1 + (2/3) + (4/9) + (8/27) + ..

ID: 3923664 • Letter: C

Question

C++ programming hw help

The infinite series: s = 1 + (2/3) + (4/9) + (8/27) + .... is a geometric series that converges to a whole rational number (i.e. like 2 or 3 or 4). Below is an unfinished C++ program that will calculate s to the kth position (so, for example, if k = 1, then s = 1 + (2/3) = 1.666...). Fill in the missing code:

Compile and run the above completed program. What is the value of s if k = 5? if k = 20? What whole rational number does s look like it's approaching? What is the smallest value of k for s to be shown by the program as exactly equal to that whole number?

Explanation / Answer

Value for 5 is : 2.73

Value for 20 is : 2.999

3 is the whole number s is approaching to with above value.

for k = 32 it will reach to value 3

#include <iostream>
#include <math.h>
using namespace std;

int main(){
double s(0.0);
int k(0);
double base = 2.0/3.0;
cout << "Enter k: ";
cin >> k;
double i=0.0;
for(i=0;i<=k;i++)
{
s = s+pow(base,i);
}
cout << "Series converges to: " << s << endl;
return 0;
}

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