class1.cs
来自「这是.net2005学习不可缺少的教程」· CS 代码 · 共 88 行
CS
88 行
using System;
namespace ZS
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
//方法一
int count1=0;
for(int i=2;i<=1000;i++)
{
bool state=false;
for(int j=2;j<i;j++)
{
count1++;
if(i%j==0)
{
state=true;
}
}
if(!state)
{
Console.Write("{0}\t",i);
}
}
Console.WriteLine();
Console.WriteLine("==========Counts is {0}============",count1);
//方法二
int count2=0;
for(int i=2;i<=1000;i++)
{
bool state=false;
for(int j=2;j<=(int)(Math.Sqrt(i));j++) //*****************
{
count2++;
if(i%j==0)
{
state=true;
}
}
if(!state)
{
Console.Write("{0}\t",i);
}
}
Console.WriteLine();
Console.WriteLine("==========Counts is {0}============",count2);
//方法三
int count3=0;
for(int i=2;i<=1000;i++)
{
bool state=false;
for(int j=2;j<=(int)(Math.Sqrt(i));j++)
{
count3++;
if(i%j==0)
{
state=true;
break; //*****************************
}
}
if(!state)
{
Console.Write("{0}\t",i);
}
}
Console.WriteLine();
Console.WriteLine("==========Counts is {0}============",count3);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?