Note, TUHS probably isn't the *best* forum to ask for help with basic C programs. :-)
That said, I suspect you mis-transcribed the program and that the line, `sum = sum + 1;` should be `sum = sum + i;`, or more idiomatically, `sum += i;`. Indeed, the whole program could be written:
#include <stdio.h>
int
main(void)
{
int i, sum = 0;
for (i = 1; i <= 100; i++)
sum += i;
printf("%d\n", sum);
return 0;
}
If you're using a C99 or later compiler, you can be slightly more succinct:
int
main(void)
{
int sum = 0;
for (int i = 1; i <= 100; i++)
sum += i;
printf("%d\n", sum);
return 0;
}
Hope that helps!
- Dan C.