当前位置:编程学习 > C#/ASP.NET >>

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

 
[csharp] 
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# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,