Get each decimal digit from the integer number, sum up them, if they can be divisible by 3. the number is multiple of 3
Like 123456,
1+2+3+4+5+6=21
1+2=3 so 123456 can be divisible by 3.
Bool Foo(int num)
{
While(true)
{
num=Sum up all decimal digits of num;
If(num==3||num==6||num==9)
Return true;
If(num<3)
Return false;
}
No comments:
Post a Comment