
如果一个数字的各位数字的立方和等于该数字本身,则称其为阿姆斯特朗数。这是一个数学概念,通常用于编程中构建程序员的基本逻辑。
Input:370 Output:370 is an Armstrong Number
370 = 3*3*3 + 7*7*7 + 0*0*0 = 27 + 343 + 0 = 370
include <iostream>
using namespace std;
int main() {
int n, num, rem, sum = 0;
cin >> n;
num = n;
while(num != 0) {
digit = num % 10;
sum += digit * digit * digit;
num /= 10;
}
if(sum == n)
printf("%d is an Armstrong number.", n );
else
printf("%d is not an Armstrong number.",n);
return 0;
}
以上就是C程序检查阿姆斯特朗数?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号