Check if a number is divisible by 3

后端 未结 16 2899
予麋鹿
予麋鹿 2020-12-01 01:30

I need to find whether a number is divisible by 3 without using %, / or *. The hint given was to use atoi() function. Any

16条回答
  •  庸人自扰
    2020-12-01 01:59

    You didn't tag this C, but since you mentioned atoi, I'm going to give a C solution:

    int isdiv3(int x)
    {
        div_t d = div(x, 3);
        return !d.rem;
    }
    

提交回复
热议问题