Please answer quickly Q. No. 1
Answers
Answer: 1 2.0 4.0 8.0 16.0
31.00
Explanation:
of series 1 + x^2 + x^3 + ....+ x^n
#include <math.h>
#include <stdio.h>
double sum(int x, int n)
{
double i, total = 1.0, multi = x;
printf("1 ");
for (i = 1; i < n; i++) {
total = total + multi;
printf("%.1f ", multi);
multi = multi * x;
}
printf("\n");
return total;
}
int main()
{
int x = 2;
int n = 5;
printf("%.2f", sum(x, n));
return 0;
}
Required program in python:
x = 5
r = -x
n = int(input("Value of exponent: "))
S = x*((-x)* *n-1)/(-x-1)
print(f"The sum of series is {S}")
Explanation:
The given series is a GP with first term x and common ratio -x. Sum of n terms of GP is given by following formula:
So for our given GP, the formula is,
We will use this formula in our program.
For sample output, refer to the attachment.