Getting wrong answer

problem :
solution :

It seems that my logic is correct at some extent but I am getting wrong answer because of less number of digit after decimal i.e my code is not giving result with good precision however I used double instead of float.
Please fix this.

edit :
At given sample input -
o/p : Case 1: 4.8284271247
but my code gives -
o/p : Case 1: 4.82843

1 Like

To take care of precision issues, use printf() as follows :
printf("%.10lf", ans);

NOTE : Number after %. is actually the precision.

Hope it helps!

1 Like

Maybe you can try long double

1 Like
precision error is fixed still I am getting wrong answer however at sample input it gives correct result.