C#练习
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//重复让用户输入输入一个数,判断该数是否质数,当输入“q”时,程序运行结束!(质数的判断要求用方法来实现)。
namespace 平时练习
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("please input a num:");
string numberstring = Console.ReadLine();
while (numberstring != "q")
{
int numint = Convert.ToInt32(numberstring);
bool result = Panduan(numint);
if (result == true)
Console.WriteLine("{0}is zhishu", numint);
else
Console.WriteLine("{0} is not zhishu",numint);
Console.WriteLine("please input a num:");
numberstring= Console.ReadLine();
Console.ReadKey();
}
}
private static bool Panduan(int numint)
{
bool result = true;
double x = Math.Sqrt(numint);
for (int i = 2; i <= x;i ++ )
{
if (numint % i == 0)
{
result = false; break;
}
}
return result;
}
}
}
{:2_27:} 新人来参考 :D
页:
[1]