#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace Std;
#define MAXNUM 1000//For all primes within 1000
int main ()
{
int I, j, C = 0;
int prime[maxnum+1];//defines an array to hold prime numbers
for (i = 2; I <= maxnum; i++)//Initialize array
{
Prime[i] = 1;//flag is 1 primes
}
for (i = 2; i*i <= maxnum; i++)//cycle processing before I
{
if (prime[i] = = 1)//If it is a prime number, filter
{
for (j = 2 * i; J <= Maxnum; j + +)
{
if (prime[j]==0)//Remove composite
{
Continue
}
if (j%i = = 0)//If it is not a prime number, it is composite, the flag of the prime number is changed to 0
{
PRIME[J] = 0;
}
}
}
}
for (i = 2; i < maxnum; i++)//value and number of output primes
{
if (prime[i] = = 1)
{
printf ("%4d", I);
C + +;
if (c% 10 = = 0)
printf ("\ n");
}
}
printf ("\ n A total of%d prime numbers", c);
System ("pause");//means pause
return 0;
}
The realization of the Eratosthenes algorithm for the determination of prime number