Computer Science, asked by neelndesai, 8 months ago

Write a program in java to find the sum of the given series: i) S = 1+1+2+3+5+………………..to n terms ii) S = 2-4+6-8+………………………to n iii) S = a - a3/5 + a5/9 – a7/13 …………………..to n terms

Answers

Answered by harnathyadav2907
0

// C++ program to find the sum of

// the given series

#include <stdio.h>

#include <math.h>

#include <iostream>

using namespace std;

// Function to return the

// sum of the series

float getSum(int a, int n)

{

// variable to store the answer

float sum = 0;

for (int i = 1; i <= n; ++i)

{

// Math.pow(x, y) returns x^y

sum += (i / pow(a, i));

}

return sum;

}

// Driver code

int main()

{

int a = 3, n = 3

Similar questions