How to check that numbers "a" and " b", a digit at a position "i" from number "b" is less or equal than the digit at position "i" at number "a"?

104 Views Asked by At

How to check that for given natural numbers "a" and " b", a digit at a position "i" from number "b" is less than the digit at position "i" at number "a" without iterating digit by digit?

e.g.

for :

a = 22222

b = 10001 is ok but b= 10030 is not ok.

I know that in case digits are less or equal then the subtraction can be done without "borrowing" but how can I validate if a subtraction was done with "borrowing" or not ?

1

There are 1 best solutions below

0
On BEST ANSWER

use mod function followed by integer division and comparison. For example if you want to compare 22222 and 10030 at the position where the 3 occurs, first take mod100mod100 so you have 22 and 30. Next integer divide by 10 (ignore the remainders) so now you have 2 and 3. Compare them >> by Mirko