问题及代码:
///*
//* Copyright (c) 2014, 烟台大学计算机学院
//* All rights reserved.
//* 文件名称:test.cpp
//* 作 者:宋健
//* 完成日期:2016年 3月 12日
//* 版 本 号:v1.0
//*
//* 问题描述:设计一个程序,输出所有的三位水仙花数。
//* 程序输入:
//* 程序输出: 三位整数里的所有水仙花数
//*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i,x,y,z;
for ( i = 100; i < 1000; i++)
{
x = i % 10;
y = (i / 10) % 10;
z = i / 100;
if (i==x*x*x+y*y*y+z*z*z)
{Console.WriteLine("{0}是水仙花数",i);
}
}
Console.ReadKey();
}
}
}
运行结果:
知识点总结:
找一类数首先要查清楚特点,然后可以的话用枚举法筛选输出