the problem is from a algorithm problem I do recently,but I can't gain the right answer [duplicate]

You don’t see anything because the condition results to false. Your variable a is float, while 1.0/k in if clause is double. They have different precision and therefore are not equal. In general it is a bad idea to compare floats on equality.

Leave a Comment