用筛选法求100以内的素数
#include<iostream>
using namespace std;
int main()
{
int a = 100,b=10,i,n;
char ch[100];
for (i = 0;i < a;i++)
ch[i] = 0;
ch[0] = 1;
for (n = 1;n <= a;n++)
{
if (ch[n - 1] == 0)
{
cout << n << " ";
for (i = n;i <= 100;i = i + n)
ch[i - 1] = 1;
}
}
}