Computer Science, asked by gulshaara1002, 4 months ago

wap to find the sum of series given :A1/1 +A2/4+A3/9+A4/16+.................... n terms​

Answers

Answered by himanshu2006vps
1

Answer:

// Java program to find the sum of the given series

import java.util.Scanner;

public class HelloWorld {

// Function to return the sum of the series

public static 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 / Math.pow(a, i));

}

return sum;

}

// Driver code

public static void main(String[] args)

{

int a = 3, n = 3;

// Print the sum of the series

System.out.println(getSum(a, n));

}

}

Similar questions