Please refer line number 16 tried with real numbers 1.5 and 2.5. It is working with 2.5 and hope if I do so it will work for rest But its a Big O(n) type approach its not so good please help