Answer to Question #57574 in C++ for manisha

Question #57574
Write a program im c++ to print the prime numbers between 100-200
1
Expert's answer
2016-02-02T06:36:11-0500
#include <math.h>
#include <vector>
#include <iostream>

using namespace std;

const int PRIME_LOWER = 100,
PRIME_UPPER = 200,
FIRST_PRIME = 2;

int main()
{
vector<bool> prime(200,true);

int x = ceil(sqrt(PRIME_UPPER));


for(int i = FIRST_PRIME; i < x; i++)
if(prime.at(i) == true)
for(int j = i; j < (PRIME_UPPER / i); j++)
prime.at(j * i) = false;


for(int k = PRIME_LOWER; k < PRIME_UPPER; k++)
if(prime.at(k) == true)
cout << k << ' ';


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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS