
对于给定的数字n,我们需要找出是否n的所有数字都能整除它,即如果一个数字是'xy',那么x和y都应该能整除它。
示例
输入 - 24
输出 - 是
解释 - 24 % 2 == 0, 24 % 4 == 0
使用条件语句检查每个数字是否非零且能整除该数字。我们需要迭代每个数字,并检查该数字是否能整除给定的数字。
例子
#include <stdio.h>
int main(){
int n = 24;
int temp = n;
int flag=1;
while (temp > 0){
int r = n % 10;
if (!(r != 0 && n % r == 0)){
flag=0;
}
temp /= 10;
}
if (flag==1)
printf("The number is divisible by its digits");
else
printf("The number is not divisible by its digits");
return 0;
}输出
The number is divisible by its digits










