+ 3
Hey friends please explain me the code and say why its output is 9...
include <iostream> using namespace std; int main() { int sum =0; int count=1; while(sum<8){ sum+=count; count =count+2; } cout<<sum; return 0; } //out put is 9
1 Antwort
+ 2
in the while loop
* the first loop
sum = 0 + 1 = 1;
count = 1 + 2 = 3;
*the second loop
sum = 1 + 3 = 4;
count = 3 + 2 = 5;
*the third loop
sum = 4 + 5 = 9;
count = 5 + 2 = 7;
at this time the while loop stop because the value of sum is 9 so it is greater than 8.
so the final value of sum is 9
and the final value of count is 7