马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

判断完全平方数

[复制链接]
查看7602 | 回复2 | 2013-12-15 21:12:35 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[backcolor=silver]//判断一个正整数是否为完全平方数?[/backcolor]
namespace 平时练习
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个数:");
            string numberString = Console.ReadLine();
            int number = Convert.ToInt32(numberString);
            bool reault=Judge(number);
            if (reault == true)
                Console.WriteLine("{0} is 完全平均数", number);
            else
                Console.WriteLine("{0} is not 完全平均数",number);
        }

        private static bool Judge(int number)
        {
            bool result = false;
double x = Math.Sqrt(number);
            for (int i = 0; i <= x; i++)
            {
                if (i * i == number)
                {
                    result = true; break;
                }
            }
            return result;
        }
    }
}
ibcadmin | 2013-12-15 22:15:46 | 显示全部楼层
加精华
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
tiantianquan | 2013-12-19 00:22:55 | 显示全部楼层
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则