Write an algorithm to find whether a given number is a multiple of 3 or not without using modulo or division operation.
Ans: Convert the number to a string, thereby getting the decimal digits separately. Read those digits once by one and add all of them. If the sum is more than 10, repeat the procedure. Once the sum is less than 10, if it is 0, 3, 6 or 9, then the original number is divisible by 3.
0 comments:
Post a Comment