My program compiles fine in CC but incorrectly in GCC:
Code:
#include <stdio.h>
#include <math.h>
int main()
{
double x, i, S;
// 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21
for (x = 1; x <= 21; x+=2) {
i = 1 / (x * x);
S += i;
}
printf ("S = %.5f \n\n", S);
}
When I compile it using gcc q1.c, I get the following result:
S = -22452648517046770147310326100015052338938211161632 56053844213213800554480952418149539187719731500677 82115693990359088513302094872312653146249325474798 85186409959787744993289388394969833238213987598470 26418386525679599720569829779511389690075766458348 07024348080598449351276885195608688031639648498086 04135424.00000
When I compile my program using the cc q1.c command, I get the correct result:
S = 1.21099
Anyone know what's causing the disparity and how to get my code to compile correctly in GCC?