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 教师闺蜜祝福语简短