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; }