您的位置:首页 > 其它

写一函数判断某数是否“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。

2014-05-18 21:31 746 查看
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<Windows.h>

void judgeArmstrongnumber(int a1)
{
int b1[3] = { 0 };
int c1 = a1;
for (int i = 0; i < 3; i++)
{
b1[i] = c1 % 10;
c1=c1 / 10;
}
if (a1 - pow(b1[0], 3) - pow(b1[1], 3) - pow(b1[2], 3)==0)
printf("%d是水仙花数\n", a1);
}
void main()
{
for (int i = 100; i < 999; i++)
{
judgeArmstrongnumber(i);
}
system("pause");
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐