Computer Science, asked by dhrjpati123, 9 months ago

write a program to find the sum of series 2 + 4 +6 + n th term in java

Answers

Answered by gauravarduino
2

Explanation:

We loop all even number upto n, and then subtract multiples of 4 and add the rest.

public class SumOfSeries{

public static void main(String args[]){

int n = 20;int sum =0;

for(int i=2;i<=n;i=i+2){

if(i%4==0){ sum=sum-i;}

else{ sum=sum+i;}

}

System. out. println("Sum of series upto " + n + " terms is : " + sum);

Answered by arjun6355m
50

Answer:

your question for arithmetic progression ( series )

this question about 1st n even number total

Sn = n²+n

S1 = (1)²+1 = 2

S2 = (2)²+2 = 6

S3 = (3)²+3 = 12

S4 = (4)²+4 = 20...

i hope u satisfied with my answer..

please like ans..

Similar questions