水仙花数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class 水仙花
{
static void Main(string[] args)
{
for (int i = 100; i < 1000; i++)
{
//百位数字
int a = i / 100;
//十位数字
int b = i / 10 % 10;
//个位数字
int c = i % 10;
//比较是不是水仙花
if (a * a * a + b * b * b + c * c * c == i)
{
Console.WriteLine(i);
}
}
Console.ReadKey();
}
}
}
总结,由于学过java语言,在java语言中写过水仙花数,所以在c#中写的时候直接套用java中的思路,语句简单明了!