2014-11-04T11:15:09-05:00
write a program to display the prime numbers.
1
2014-11-06T10:50:29-0500
#include <cstdlib> #include <iostream> using namespace std; int main() { int i, j,S; //index int N; //size of array bool *mas; //bool array cout << "Prime numbers till N \n"; cout << "Enter number N "; cin >> S; N=S+1; mas= new bool [N]; //dynamic array N for(i=1; i<=S; i++) mas[i]=true; for(i=2; ((i*i)<=S); i++) if(mas[i]) for(j=(i*i); j<=S; j+=i) if(mas[j]) mas[j]=false; //print array for(i=1; i<=S; i++) if(mas[i]) cout << i << " "; system("pause"); return 0; system("PAUSE"); return EXIT_SUCCESS; }
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