Write a efficient functions to find floor of x. Given a sorted array and a value x, the floor of x is the largest element in array smaller than or equal to x. Write…