I'm compiling the below C code with gcc
. No errors are thrown during compilation or at runtime. I ran through the code with gdb
, and the answer given in sum
is correct at the end, yet the printf()
does not display anything on the screen. I've tried all sorts of combinations of fprintf()
, printf()
, and fflush()
, but nothing works.
What do I need to change so the program will print the result to stdout
?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num = 9;
int i, sum; i = 1, sum = 0;
while (i < 2 * num) {
sum = sum + i * i;
++i;
}
printf("sum: %d\n", sum);
fflush(stdout);
return 0;
}