对于给定的数字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
以上就是C程序检查一个数字的所有位数是否能整除它的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号