检查号码是Armstrong还是不使用C
问题
如何使用C编程语言检查给定的号码是否是Armstrong号码?
解决方案
阿姆斯特朗数是等于其数字的立方之和的数字。
语法
pqrs………=pow(p,n)+pow(q,n)+pow(r,n)+……….
例如,153,371,1634等是阿姆斯特朗编号。
153=1*1*1 + 5*5*5 + 3*3*3 =1+125+27 =153 (Armstrong number)
程序
#include输出结果int main(){ int number,remainder,total=0,temp; printf("enter the number="); scanf("%d",&number); temp=number; while(number>0){ remainder=number%10; total=total+(remainder*remainder*remainder); number=number/10; } if(temp==total) printf("This number is Armstrong number"); else printf("This number is not Armstrong number"); return 0; }
enter the number=371
This number is Armstrong number
Check: 371=3*3*3 +7*7*7 + 1*1*1
=27 + 343 +1
=371
enter the number=53
This number is not Armstrong number解释
53 = 5*5*5 + 3*3*3 =125 +27 = 152 != 53
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短