The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Mark Longridge <cubexyz@gmail.com>
To: Donald ODona <mutiny.mutiny@india.com>
Cc: "tuhs@minnie.tuhs.org" <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] A c program problem
Date: Wed, 22 Aug 2018 08:54:17 -0400	[thread overview]
Message-ID: <CADxT5N75gW=xq7tjDW+Zi_6ZoiCBqEA8YToFU3N4co7zrsmzwQ@mail.gmail.com> (raw)
In-Reply-To: <1281463715.239847.1534940666012.JavaMail.tomcat@india-live-be04>

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@india.com> wrote:
>
>
> At 22 Aug 2018 12:18:08 +0000 (+00:00) from cc <caipenghui_c@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@163.com
>> |
>>
>> 签名由 网易邮箱大师 定制
>

  reply	other threads:[~2018-08-22 12:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 12:01 cc
2018-08-22 12:24 ` Donald ODona
2018-08-22 12:54   ` Mark Longridge [this message]
2018-08-22 14:21 ` Dan Cross
2018-08-22 14:26   ` cc
2018-08-22 14:29     ` cc
2018-08-22 14:32       ` Ralph Corderoy
2018-08-22 14:34         ` cc
2018-08-22 15:40       ` Toby Thain
2018-08-22 15:46         ` Caipenghui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADxT5N75gW=xq7tjDW+Zi_6ZoiCBqEA8YToFU3N4co7zrsmzwQ@mail.gmail.com' \
    --to=cubexyz@gmail.com \
    --cc=mutiny.mutiny@india.com \
    --cc=tuhs@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).