Computer Science, asked by jaychaurasia30, 21 days ago

Please answer quickly Q. No. 1

Attachments:

Answers

Answered by LegalRoadster22
1

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;

}

Answered by Anonymous
5

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:

\boxed{\sf S_n = \dfrac{a(r^n -1 )}{r-1}}

So for our given GP, the formula is,

\boxed{\sf S_n = \dfrac{x((-x)^n-1)}{(-x-1)}}

We will use this formula in our program.

For sample output, refer to the attachment.

Attachments:
Similar questions