difference = 1.0…

This means denominator is equal to numerator… As “grad” is not touched in a loop, most likely gradapprox =0. Please check the value for gradapprox, as the first step. It can be done by a typo of a sign for epsilon, and some others…

grad and gradapprox both are equal.

I believe you are working on gradient_check_n().

If grad and gradapprox are equal, then, numerator becomes zero. So, difference = 0, not 1.0.

Thank you, Sir. There was a typo.