This function:
#include <iostream>
bool isStrictlyIncreasing(int x) {
int lastDigit = x % 10;
int leadingDigits = x / 10;
while (leadingDigits > 0) {
int digit = leadingDigits % 10; if (digit >= lastDigit)
return false;
lastDigit = digit;
leadingDigits = leadingDigits / 10;
}
return true;
}
int main()
{
int tests[] {2, 11, 13, 20, 123, 120, 1243, 2334};
for (int i = 0; i < 8; ++i) {
std::cout<< tests[i] << " is increasing: " << isStrictlyIncreasing(tests[i]) << "\n";
}
char c;
std::cin >> c;
return 0;
}
returns this output:
2 is increasing: 1
11 is increasing: 0
13 is increasing: 1
20 is increasing: 0
123 is increasing: 1
120 is increasing: 0
1243 is increasing: 0
2334 is increasing: 0
Is that what you were looking for?