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 赠书祝福语简短文案
18 学姐和学妹祝福语简短