Using while loop calculate the sum, square and square root of even numbers ranging from 1-100 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Using while loop calculate the sum, square and square root of even numbers ranging from 1-100

23rd Nov 2016, 11:20 AM
Stephanie Ogbudu
Stephanie Ogbudu - avatar
2 Answers
+ 2
var s=0,i=0; while(i!=100) { s+=Math.sqrt(i); // for power use Math.pow(i,2) function i+=2; } remember this is not a copy past solution. You have to write rest of the code. I am sure you can it is easy
23rd Nov 2016, 11:28 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
Declare an index i for your while loop and assign 2. Declare another variable sum. Then declare your while loop with the condition that i is less than 101. Everytime you go into your while loop. You add your current index i to sum and print i*i and the squareroot of i. At the end, after your while loop print sum.
23rd Nov 2016, 11:30 AM
Andreas K
Andreas K - avatar