+ 2

What is wrong in following loop? while(p<=100) sum+=p*p

while loop

1st Sep 2018, 4:57 PM
Himanshu Mathur
4 Respuestas
+ 7
int p = 1, sum = 0; while(p <= 100) { sum += p * p; p++; }
1st Sep 2018, 8:22 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 4
p isn't incremented in the loop so p can't never be equal to 100!
1st Sep 2018, 5:11 PM
Théophile
Théophile - avatar
+ 4
variables p and sum are not initialized, lost semicolons after p * p. there is no loop exit condition, because p does not change
1st Sep 2018, 6:10 PM
Miguel Angel Acosta
Miguel Angel Acosta - avatar
+ 3
p does not change is value so it becomes an infinite loop, the condition is always true
1st Sep 2018, 5:24 PM
michal