Answer to Question #18389 in C++ for Ige
how to write a C++ program to find all the prime numbers between 1 and 20000
1
2012-11-13T10:28:57-0500
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <time.h>
using namespace std;
#include <vector>
int Eratosfen (int n)
{
vector <bool> pA (n+1); //масив використовується з індекса 2
for (int i=0 ; i<n ; ++i)
& pA[i]=0;
int count = n-1;
for (int i=2; i*i<=n ; i++)
{
&
& if (pA[i]==0)
& for (int j=i*i; j<=n ; j+=i)
& if (pA[j]==0)
& {
&
& pA[j]=1;
& count--;
& }
}
for (int i = 0 ; i < pA.size() ; i++){
& if (pA[i] == false) cout<<i<<endl;
}
return count;
}
int main ()
{
Eratosfen(20000);
system ("pause");
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment