您的位置:首页 > 编程语言 > C#

c# { 1 } 1000以内的水仙花数

2012-10-22 16:35 405 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace number
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("三位数中:");
for (int i = 100; i <= 999; ++i)
{
if (num(i) == true)
{
Console.WriteLine("{0}是水仙花数", i);
}
else
{
continue;
}
}
Console.ReadKey();
}

static bool num(int number)
{
int d3 = number / 100;
int d2 = number % 100 / 10;
int d1 = number % 100 % 10;

int N = d3 * d3 * d3 + d2 * d2 * d2 + d1 * d1 * d1;

if (number == N)
{
return true;
}

return false;
}
}
}

 

实验结果:



 

上机感言:这是第一次发c#程序,本来想放弃来,但感觉懂点总比不懂好吧,毕竟咱是干程序的,各种语言必须涉猎一些。。。以后还会继续上C#程序的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# string class 语言