Skip to content

Instantly share code, notes, and snippets.

@anirudh-ramesh
Created October 6, 2016 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anirudh-ramesh/9bfaa20477ebf319bd8aafe210519f97 to your computer and use it in GitHub Desktop.
Save anirudh-ramesh/9bfaa20477ebf319bd8aafe210519f97 to your computer and use it in GitHub Desktop.
Align positive number to nearest multiples of another
#include <iostream>
using namespace std;
#define alignUp(value, factor) (((value + (factor - 1)) / factor) * factor)
#define alignDown(value, factor) ((value / factor) * factor)
int main(int c, char **v)
{
cout << alignUp(stoi(v[1], nullptr), stoi(v[2], nullptr)) << " " << alignDown(stoi(v[1], nullptr), stoi(v[2], nullptr)) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment