Computer Science, asked by rajeswaripurohit1, 10 months ago

write a program to find the sum of the following series S = a – a³ + a^5 – a^7 + . . . . . . . . . . . . . . to n​

Answers

Answered by nupur3930
2

Answer:

import java.util.*;

class sum

{

public static void main (String args[])

{

Scanner sc=new Scanner (System.in);

System.out.println("Enter the value of n");

if(n%2==0)

{

n=n-1;

}

int sum= 0;

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

{

if(x%2!=0

{

sum = sum+ Math.pow(a,x);

}

else

{

continue;

}

}

System.out.println(sum);

}

}

Similar questions