>>201
printf("\n ans = %d\n",ans);

printf("\n ans = %lf\n",ans);
に書き換えてみてください。

それか、ansをint型にしてみてください。