if (i == bai * bai * bai + shi * shi * shi + ge * ge * ge)
{
Console.WriteLine("水仙花数:" + i + "
");
}
}
复制代码
这么写。也理解了。
请问一下 五角星数如何写呢?作者: 林其荣 时间: 2013-1-18 21:57
for (int i = 0; i < 100000; i++)
{
int shiwan = i / 10000;
int shiwanyushu = i % 10000;
int wan = shiwanyushu / 1000;
int wanyushu = shiwanyushu % 1000;
int qian = wanyushu / 100;
int qianyushu = wanyushu% 100;
int bai = qianyushu / 10;
int baiyushu = qianyushu % 10;
int shi = baiyushu / 1;
int shiyushu = baiyushu % 1;
int ge = shiyushu ;
if (i == shiwan * shiwan * shiwan * shiwan * shiwan + wan * wan * wan * wan * wan + qian * qian * qian * qian * qian + bai * bai * bai * bai * bai + shi * shi * shi * shi * shi + ge * ge * ge * ge * ge)
{
Console.WriteLine(i);
}
}
//五角星数的写法楼主参考下作者: 林嘉健 时间: 2013-1-19 20:56
ok 这方法确实可以