早教吧作业答案频道 -->其他-->
关于C#中一个方法的使用问题staticboolIsPrime(intnum)如果num是素数便返回true,不然返回false并且使用一个while循环,利用以上method来展示0到1000之间的素数原题:Assumethefollowingmethodisavailab
题目详情
关于C#中一个方法的使用问题
static bool IsPrime (int num)
如果num是素数便返回true,不然返回false
并且使用一个while循环,利用以上method来展示0到1000之间的素数
原题:
Assume the following method is available for use:
static bool IsPrime (int num)
IsPrime takes a number and returns true if the number is prime, otherwise it returns false. (A number is said to be prime if it is only divisible by 1 and by itself).
Write a
while loop to display every prime number between 0 and 1000 using the above method. (That is, do NOT implement IsPrime)
static bool IsPrime (int num)
如果num是素数便返回true,不然返回false
并且使用一个while循环,利用以上method来展示0到1000之间的素数
原题:
Assume the following method is available for use:
static bool IsPrime (int num)
IsPrime takes a number and returns true if the number is prime, otherwise it returns false. (A number is said to be prime if it is only divisible by 1 and by itself).
Write a
while loop to display every prime number between 0 and 1000 using the above method. (That is, do NOT implement IsPrime)
▼优质解答
答案和解析
//此处只计算正整数的质数
public static bool IsPrime(int num)
{
if(num<2)
{
return false;
}
if(num==2)
{
return true;
}
for(int i=2;i<num;i++)
{
if(num%i==0)//如果能整除 就返回false
{
return false;
}
}
return true;
}
//展示0-1000之间的素数
public void Main()
{
int n = 0;
while(true)
{
if(n>=1000)break;
if(IsPrime) Console.WriteLine(n);
}
}
看了 关于C#中一个方法的使用问题...的网友还看了以下:
看图补全对话A:&&adag?B:&,itisacat.A:whatis&B:Mimi.M-I-M 2020-05-17 …
纯贴现债券到期一次还本付息,单利计息(必要报酬率按照复利计算).PV=(M+I*n)*(P/S,i 2020-05-21 …
"没身不殆"中的"没"怎么读汉典显示读音是“méi”,我个人感觉应该是“mò”,因为“mò”的解释 2020-06-10 …
我发现了一个美妙的定理,请问一下这个定理以前有没有人发现过矩阵特征多项式展开定理:n阶矩阵A的特征 2020-06-19 …
这个程序要求是输出m个数中任取n个数的所有组合,我要抓狂了==#include;#includei 2020-06-28 …
运行程序的结果,为什么,#includefunc(inta,intb){staticintm=0, 2020-07-22 …
给多音字组词。没méi()给多音字组词。没méi()为wéi()朝cháo()磨mò()mò()w 2020-07-28 …
数学题0818集合M={-1,0,1,-2,2,10,20,-30,99,-100}有10个元素, 2020-07-29 …
已知i是虚数单位,若(m+i)2=3-4i,则实数m为答案是这个(m+i)^2=3-4im^2+2 2020-08-02 …
数学题0727(5)集合M={-1,0,1,-2,2,10,20,-30,99,-100}有10个元 2020-11-01 …