c#中水仙花数怎么变成,如153=1*1*1+5*5*5+3*3*3是一个水仙花数

如题所述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 水仙花数
{
class Program
{
static void Main(string[] args)
{
//for循环练习题。
//输出100到999之间所有的水仙花数。水仙花数是个位数、十位数、百位数分别的三次方的和恰好等于这个数。

for (int i = 1; i <= 9; i++)//i为百位上的数字。
{
for (int n = 0;n <= 9; n++)//n为十位上的数字。
{
for (int m = 0; m <= 9; m++)//m为个位上的数字。
{
if ((i * 100 + 10 * n + m ) == (i * i * i + n * n * n + m * m * m))//三个的分别的三次方的和等于这个三个数。
{
Console.WriteLine("100到999之间的水仙花数为{0}", (i * 100 + 10 * n + m ));

}
}
}
}
Console.ReadKey();
}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-05-09
1.写个程序打印出"Hello world"..
2.写个程序并提供一个打印出"Hello world"的方法,并调用该方法打印出"Hello world"..
3.写个程序提供一个打印出"Hello world"的方法(需要一个int参数),并根据传入的参数打印相应次数的"Hello world"...
.................
相似回答