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 婚前女儿生日祝福语简短