查找将C除以数字的数字位数
假设给出一个数字。我们必须计算数字的位数,然后将数字平均分配。假设数字为1012,结果为3。三位数1、1和2将1012平均除。
为了解决这个问题,我们将使用模运算来找到数字的每个数字,并检查数字是否可被该数字整除,如果可以整除,则增加计数器。如果数字为0,则忽略该数字。
示例
#include<iostream>
using namespace std;
int countDivDigit(int num) {
int count = 0;
int temp = num;
while(temp){
int div = temp%10;
if(div != 0){
if(num % div == 0)
count++;
}
temp /= 10;
}
return count;
}
int main() {
int num = 1012;
cout << "Number of digits that divides " << num << " evenly, is: " << countDivDigit(num);
}输出结果
Number of digits that divides 1012 evenly, is: 3
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语