0
why is result 25 when the sum in fact 23?
#include <stdio.h> int main() { int count = 11; int ssumm; while (count <= 18) { printf(" Count = %d\n", count); printf (":\n "); count++; ssumm = ssumm + count ; if (count == 13) break ; } printf (" iam zasum just afta zalup ova %d\n", ssumm );//result is 25? return 0; }
5 Antworten
+ 9
When loop will run first time then 11 will print in first then count++ it will increase by 1 and it will become 12
ssumm=0+12; so ssumm=12 then again loop will run
count ++ so present value of count is 13
ssumm=12+13 so answer is 25
+ 3
ssumm is unintialized, so lets assumming its 0.
in first step
ssumm = ssumm + count;
12 = 0 + 12
in second step
25 = 12+13
now count is 13, so break
+ 2
First it ran with 11.
Satisfied the while loop.
When you incremented count++
Count became 12.
Sum was initially 0 but now is 12.
Again satisfied while loop with count = 12.
Incremented to 13.
Sum: which was 12 before added to 13, and that makes 25.
Now that count = 13 broke out of while loop.
Finally prints sum=25.
0
12 +13 =25
0
thnx friendz