The number//screening method is: "Erato screening Method"//Find a non-prime to dig it off, the last is the prime number * * To find out the prime number of the 1~n * 1, Dig 1 * 2, with the next not to dig the numbers p remove the number of p, the multiples of p to dig out * 3, check P Is the integer part less than n (if n=1000, stick to p<31?), * if it is, then return (2) to continue execution, otherwise end. * 4, the remainder is the prime number * * #include <iostream> #include <iomanip>using namespace std; #include <cmath>int main () { int I, J, N, a[101];for (i = 1; i <=; i++) {a[i] = i;} A[1] = 0;for (i = 2; I < sqrt (+); i++) {for (j = i + 1; J <=, J + +) {if (a[i]! = 0 && a[j]! = 0) {if (a [j]% a[i] = = 0) {A[j] = 0;}}} Cout<<endl;for (i = 1, n = 0; I <=; i++) {if (a[i]! = 0) {COUT<<SETW (5) <<a[i]<< ""; n++;} if (n = =) {cout<<endl;n = 0;}} cout<<endl; return 0;}
To find prime numbers by filtering method