@chelchax It was clear upon first read that the code you posted was muddled about the roles of h and N (with initial point a and target end-point b also supplied).
Those four quantities are related mathematically. You cannot (logically) force your own choice for all four of them at once. At least one of them needs to depend formulaically upon the others.
You subsequently added a followup Comment/Reply stating that you intended to force values for h the stepsize. That's quite natural, IMO, and a common way to code this task. Hence I revised the procedure RK4 so that -- given a supplied stepsize h and end points a,b -- it would compute an N that fit closest to target b without going past. It doesn't matter whether N is computed in the body of RK4, or in the call to it. What matters is here is that N depends on h,a, and b. It also doesn't matter much to this aspect of the argument whether you take the floor gettting almost up to b, or take the ceil to get just past b.
The image of the code that you now show does it the other way. It computes the stepsize h depending on a,b and N. That's not wrong, though IMO it looks a little awkward. It's a trivial adjustment to the code and you ought to be able to accomplish it. But you should realize that you would subsequently utilize the ensuing procedure by forcing (supplying, passing) a value for N rather than for h (since it really doesn't seem useful to have the end-point b be dependent and not specified by you). That contradicts your earlier stated requirement of intending to specify h the stepsize.
Does all that make sense?
Which do you prefer?
You could even have code that did it either way (dependent h, or dependent N), according to some option passed to the procedure. But you can't logically specify forced values for all of a,b,h, and N together.