[TUHS] A c program problem

Toby Thain toby at telegraphics.com.au
Thu Aug 23 01:40:18 AEST 2018


On 2018-08-22 10:29 AM, cc wrote:
> I want to figure out if the book is right or the compiler is right.
> 
> 	
> cc


Donald and Dan identified the issue in earlier replies.

$ cc foo.c -o foo
$ ./foo
5050
$ cat foo.c
#include <stdio.h>
int main(void)
{
       int i, sum = 0;
       i = 1;
       while ( i <= 100) {
       sum = sum + i;
       i++;
       }
       printf("%d\n", sum);
       return 0;
}

--Toby





More information about the TUHS mailing list