Curly brackets after for statement

前端 未结 4 1523
渐次进展
渐次进展 2021-01-16 16:35

I\'m a newbie. Wrote a code to print sum of number from 1 to 10. Here\'s what happened;

for(a = 1; a<=10; a++)
sum += a;
cout<
<
4条回答
  •  有刺的猬
    2021-01-16 16:56

    In the first one you are executing cout<

    In the second you are calling it every execution of the loop. That makes it print 1, then 3, then 6 ... always appending it, since there is no newline. As you can see you have 55 as last output.

提交回复
热议问题