☺ 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
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 ☺
Similar questions