Computer Science, asked by divyanshi261, 1 year ago

☺ Hye Frndz Good evening ☺

Write a program in Java to find the sum of following series :

a => 2-4+6-8+.......... to n

b=>1+(1+2)+(1+2+3)........(1+2+3+......+n)

#Computer

Thanks


Answers

Answered by Anonymous
7

Hi

function additionOfSubractionTill(limit) {

   var result = 0;

   var switcher = true;

   for (var i = 2; i <= limit; i += 2) {

       if (switcher) {

           result += i;

           switcher = !switcher;

       } else {

           result += -i;

           switcher = !switcher;

       }

   }

   console.log(result);

}

additionOfSubractionTill(8);

Attachments:

divyanshi261: Thankeww ☺
babu11110: hi
spillutla: Hello Ajay! Long time.. Can you text on the private messaging place?
spillutla: ..
Anonymous: hi.. how are you mate
Similar questions