60 642
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #18389 in C++ for Ige

Question #18389
how to write a C++ program to find all the prime numbers between 1 and 20000
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions