自动生成前十个质数的算法:(具体的代码请看cindy.cs)
1、 设置两个计数器 counter1=2,counter2 = 2;
2、 如果counter1<=10,则执行 3 如果counter1大于10则执行6
3、 当counter2<= counter1,则执行 4 如果counter2大于counter1则执行6
4、 如果counter1% counter2=0;则执行5
5、 如果counter1=counter2,显示counter1是质数,反之不是
6、 结束算法
using System;
class cindy{
public static void Main(){
for(int counter1 = 2;counter1 <= 30;counter1++){
for(int counter2 = 2;counter2 <= counter1;counter2++){
if(counter1%counter2==0){
if(counter1 == counter2){
Console.WriteLine(counter1 + "是质数");
}else{
//Console.WriteLine(counter1 + "不是质数");
break;
}
}
}
}
}
}