2025年水仙花数

水仙花数一 描述 所谓的 水仙花数 是指一个三位数其各位数字的立方和等于该数本身 例如 153 是 水仙花数 因为 153 13 53 33 在数论中 水仙花数 Narcissistic number 也称为自恋数 自幂数 阿姆斯壮数或阿姆斯特朗数

大家好,我是讯享网,很高兴认识大家。

一、描述:

在数论中,水仙花数(Narcissistic number)也称为自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),是指一N位数,其各个数之N次方和等于该数。
例如153、370、371及407就是三位数的水仙花数,其各个数之立方和等于该数:
153 = 1^3 + 5^3 + 3^3。
370 = 3^3 + 7^3 + 0^3。
371 = 3^3 + 7^3 + 1^3。
407 = 4^3 + 0^3 + 7^3。


讯享网

二、分析:

对水仙花数的求法转化为对个位数、十位数、百位数的求法。

个位数求法:i%10
十位数求法:(i/10)%10
百位数求法:i/100

三、程序:

//求出100〜999之间的所有“水仙花数”并输出。 #include<stdio.h> #include<windows.h> #include<math.h> #pragma warning(disable:4996) int main(){ 
    int i = 0; int single=0, ten=0, hundred=0; for (i=100;i < 1000; i++){ 
    int single = i % 10; //个位数 int ten =( i / 10) % 10; //十位数 int hundred = i /100; //百位数 if (i == hundred* hundred* hundred + ten* ten*ten + single*single*single){ 
    printf("%d\n", i); } } system("pause"); return 0; } 

讯享网

四、运行结果:

在这里插入图片描述

小讯
上一篇 2025-04-06 13:52
下一篇 2025-01-27 08:10

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/127277.html