判断完全平方数
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
//判断一个正整数是否为完全平方数?
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;
}
}
} {:2_27:} 加精华 {:3_46:}{:3_46:}{:3_46:}
页:
[1]