I know that C/C++ always lowers the result of dividing int.
I know that math.h
has ceil()
, but I want to know how to raise the header right away without including it.
My code is inefficient by comparing and multiplying it separately, but I want to know a better code.
q = x / y;
if (q * y < x) ++q;
Code assuming that both x and y are positive.
q = (x + y - 1) / y;
q = 1 + ((x - 1) / y);
© 2024 OneMinuteCode. All rights reserved.