[TUHS] A c program problem
Mark Longridge
cubexyz at gmail.com
Wed Aug 22 22:54:17 AEST 2018
Looks like a typographical error.
if you change the line:
sum = sum + 1;
to
sum = sum + i;
then you will get 5050.
Also the line with printf should have a semi-colon at the end.
On 8/22/18, Donald ODona <mutiny.mutiny at india.com> wrote:
>
>
> At 22 Aug 2018 12:18:08 +0000 (+00:00) from cc <caipenghui_c at 163.com>:
>> Hello everyone
>>
>> I had a problem compiling a piece of c code from the book. The result of
>> running the book is 5050, but the compiler is 100. I don't know which is
>> right, please help me to see which is wrong. Thank you very much!
>>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>> int i, sum = 0;
>> i = 1;
>> while ( i <= 100) {
>> sum = sum + 1;
>> i++;
>> }
>> printf("%d\n", sum)
>> return 0;
>> }
>>
>>
>>
>>
>> | |
>> cc
>> |
>> |
>> 邮箱:caipenghui_c at 163.com
>> |
>>
>> 签名由 网易邮箱大师 定制
>
More information about the TUHS
mailing list