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; }

22nd Jun 2020, 6:22 AM
Yohonon Makunin
Yohonon Makunin - avatar
5 ответов
+ 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
24th Jun 2020, 3:36 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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
22nd Jun 2020, 6:30 AM
Taste
Taste - avatar
+ 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.
22nd Jun 2020, 6:34 AM
Blue!!
Blue!! - avatar
0
12 +13 =25
22nd Jun 2020, 6:26 AM
JME
0
thnx friendz
22nd Jun 2020, 8:40 AM
Yohonon Makunin
Yohonon Makunin - avatar