C程序检查阿姆斯壮编号?
如果数字的立方的总和等于数字本身,则该数字称为阿姆斯壮数字。这是一个数学概念,通常在编程中用来构建程序员的基本逻辑
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;
}热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短