Https://ide.codingblocks.com/s/123212

how shoud i print the value of final upper as i am unable to access upper outside the for loop

You should initialize all your variables outside the for loop. For example, you have initialized count inside the for loop, so it will become 0 again for every iteration. And you should initialize upper and lower with -1 instead of 0 because in case the element is not found, you have to print -1 for both upper and lower bounds. Another thing you need to take care of is that your code only prints the lower bound if the element is found, but it should also print -1 if element is not found.