C programming hw help The infinite series s 1 23 49 827
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?
Solution
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;
}
