Implied volatility calculation


i am able to calculate fair price of call option and put option by a given iv, buy to calculate implied volatility i need to reverse calculate . i am unable to solve this as i need to use the above formula of fair price inside a loop.
which is not working.
can you guide me how to do this

Thanks in advace