C程序检查数字的所有数字是否都除以它
对于给定的数字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
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志