Hi there.
I am trying to write a program that approximates the integral of Cos^2, by working out the area under the graph.

It was working on my home computer, running OSX, using GCC to compile, although I gather that GCC and CC are the same thing on OSX.

But, trying to run it on my university computers (Unix) I get some crazy things happening, which seem to be caused by an issue with incrementing an integer.

The code is here.

When I compile with GCC, I get this as my output:
Code:
Count = 3555 
Count = 3556 
Count = 3557 
Count = 3558 
Count = 3559 
Count = 3560 
Count = 3561 
Count = 3562 
Count = 3563 
Count = 3564 
Count = 3565 
Count = 3566 
Count = 3567 
The integral of (Cos(x))^2 between 0.000000 and 0.560000 is -22451877030849596034839243233979729137634606950168132554244772637725918156767371541383682094482259477193717530871408213064495352486659616158821156590299808112573904456113502043764019515866649496876255051482750237449798387798526542402632640838500465932172585681913451504091616968612989814208112571000503140352.000000
But using CC, I get this:
Code:
Count = 3560 
Count = 3561 
Count = 3562 
Count = 3563 
Count = 3564 
Count = 3565 
Count = 3566 
Count = 3567 
The integral of (Cos(x))^2 between 0.000000 and 0.560000 is 0.505039
Which is close enough to the right answer. But, changing
Code:
printf("Count = %d \n",count);
to
Code:
printf("Count = %d \n",count);
I get:
Code:
Count = 7.5543e-311 
Count = 7.55642e-311 
Count = 7.55855e-311 
Count = 7.56067e-311 
Count = 7.56279e-311 
Count = 7.56491e-311 
Count = 7.56703e-311 
Count = 7.56916e-311 
Count = 7.57128e-311 
The integral of (Cos(x))^2 between 0.000000 and 0.560000 is -22451705589472446232067891485971879537344917125398259668867581637663778900599191551604083182741648965856417115723741404561003322543413905388574180837058612935377041503029104856068252778672968498937985004215835788706198650487466264022351694189797328699165952542769808519416934401735683372217923175709814030336.000000
Unfortunately for me, the code is compiled with GCC when marked
What on earth is going on?
Thanks for the help