Computer Science, asked by prajktapasare0220, 6 months ago

Write a JavaScript program to print sum of even numbers between 1 to 100 using for loop

Answers

Answered by Imblank
2

Answer:

let sum=0;

for(i = 2;i<=100;i=i+2){

sum = sum+i

}

console.log(sum);

Read my bio once

Answered by NAVA98
4

Answer:

class JavaExample {

  public static void main(String args[]) {

int n = 100;

System.out.print("Even Numbers from 1 to "+n+" are: ");

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

   //if number%2 == 0 it means its an even number

   if (i % 2 == 0) {

 System.out.print(i + " ");

   }

}

  }

}

Similar questions