Write the programs in Java to find the sum of the following series: (b) S = a - a3 + a5 - a7 + ....... to n
Answers
Answered by
17
Answer:
Hi friend.... here is ur answer
import java.util.*;
class Series
{
public static void main(String ar[])
{
Scanner sc=new Scanner (Syatem.in);
int i,n,d=1,s=0;
System.out.println("Enter a limit");
n=sc.nextInt();
System.out.println("Enter value of a");
a=sc.nextInt();
for (i=1;i<n;i++)
{
if (i%2==0)
s - = Math.pow(a,d);
else
s + = Math.pow(a,d);
d+=2;
}
System.out.println("Sum="+s);
}
}
If it helps u plz mark my answer brainliest
Explanation:
Answered by
3
Answer:
the above answer is absolutely correct so check out that and u may thank me for such an advice
Similar questions