Use a for loop in a function to calculate the sum of the fir
Use a for loop in a function to calculate the sum of the first n terms of the series: f(x) = sigma_k = 1^n -1^k + k^2 + 5k/3^k You should get n as in input argument and return the value of the summation as an output argument. Show the results of n = 10 and n = 20.
Solution
The image is not clear and I guess the eq is (-1^k + k^2 + 5k)/3^k If the operators are not correct then replace the operators as required
Here is the cpp code
double calc(int n)
{
double sum=0;
double f=0;
for(int k=1; k<=5;k++)
{
f=(pow(-1, k)+(k*k)+5*k)/pow(3, k);
sum=sum+ f;
}
return sum;
}
