write a program to find the sum of the following series S = a – a³ + a^5 – a^7 + . . . . . . . . . . . . . . to n
Answers
Answered by
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
Math,
5 months ago
Math,
5 months ago
Hindi,
5 months ago
Social Sciences,
10 months ago
English,
10 months ago
Political Science,
1 year ago
Computer Science,
1 year ago