Skip to content

Instantly share code, notes, and snippets.

@edg-l
Last active September 11, 2018 21:08
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 edg-l/1a1197e83692d6b2702f1fb92b84ad7b to your computer and use it in GitHub Desktop.
Save edg-l/1a1197e83692d6b2702f1fb92b84ad7b to your computer and use it in GitHub Desktop.
Compare digit
#include <cmath>
bool compareDigit(int a, int b, int n)
{
return (a - (a % (int)pow(10, n - 1))) % (int)pow(10, n) == (b - (b % (int)pow(10, n - 1))) % (int)pow(10, n);
}
// compareDigit(234, 134, 1) == true (4 == 4)
// compareDigit(234, 134, 3) == false (2 != 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment