1. The [b]AND[/b] operator operator you want is [u]&&[/u] not [u]&[/u].
& is bitwise AND

2. [code]if ( omega < 0.001 && omega > -0.001 )  [/code]
is not a good condition
What if acceleration is very small, omega still smaller then 0.001 in two or more time step.
And if the pendulum starts with omega=0, you might get half period only.

What about define a omegas to store previous omega and change the condition to

[code]if( omega*omegas<0){
omegas=omega;/save old value
T=t-ts;// period=time differences, not necessary starts from t=0
count=0;//you need to reset the counter, unless you only want to calculate the first period
However, the above code work only if the pendulum starts with omega=0;