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

C#程序设计(一)---水仙花数

2012-09-28 16:37 323 查看
/* (程序头部注释开始)

/* (程序头部注释开始)

* 程序的版权和版本声明部分

* Copyright (c) 2012, 烟台大学计算机学院学生 

* All rights reserved.

* 文件名称:

* 作 者: 刘镇

* 完成日期: 2012 年 09 月 28 日

* 版 本 号: 3.001

* 对任务及求解方法的描述部分

* 输入描述: ......

* 问题描述: 水仙花数

* 程序输出: ......

* 程序头部的注释结束

*/

 

 

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(false);
}

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# string class 任务 c