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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短