Computer Science, asked by emindra, 11 months ago

wap in java to find the sum of the series :s=(1*2)+(2*3)+.......to n

Answers

Answered by manavmahour65
0

(3*3) this is the right answer of this answer

Answered by lovingheart
0

Here the logic is the number has to be added to the result of multiplication of previous number and current number.

int n = 10;

int sum=0;

int previousnum = 1;

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

       previousnum += previousnum * (i+1);

sum += previousnum;

}

System.out.println(sum);

If n = 5, then (1*2)+(2*3)+(3*4)+(4*5) = 39

The main logic is implemented in the below line

       previousnum += previousnum * (i+1);

sum += previousnum;

Similar questions