For positive numbers
unsigned int x, y, q;
To round up …
q = (x + y - 1) / y;
or (avoiding overflow in x+y)
q = 1 + ((x - 1) / y); // if x != 0
More Related Contents:
- Creating all possible k combinations of n items in C++
- Finding all the subsets of a set
- Most efficient/elegant way to clip a number?
- Fastest algorithm for primality test [closed]
- Special simple random number generator
- sine wave that slowly ramps up frequency from f1 to f2 for a given time
- Efficiently getting all divisors of a given number
- Inverting a 4×4 matrix
- Fastest way to get the integer part of sqrt(n)?
- Finding square root without using sqrt function?
- Insertion sort stops working after million input
- C++ quadratic equation using factorization
- C++ – Find numbers between first and last negative numbers in Array
- The most efficient way to implement an integer based power function pow(int, int)
- Image Processing: Algorithm Improvement for ‘Coca-Cola Can’ Recognition
- Rotating a point about another point (2D)
- Create Random Number Sequence with No Repeats
- Getting the actual length of a UTF-8 encoded std::string?
- Most accurate way to do a combined multiply-and-divide operation in 64-bit?
- What is the best way to evaluate mathematical expressions in C++?
- Algorithm for finding the smallest power of two that’s greater or equal to a given value [duplicate]
- How can I sort a std::map first by value, then by key?
- what is the difference between set and unordered_set in C++?
- C – How to implement Set data structure?
- Similar String algorithm
- Calculating the Amount of Combinations
- How do I implement a Bézier curve in C++?
- Impact of cubic and catmull splines on image
- Better shading on BW display while rendering filled surfaces
- Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? [duplicate]