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
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西