67 155
Assignments Done
99,4%
Successfully Done
In November 2018

Answer to Question #57574 in C++ for manisha

Question #57574
Write a program im c++ to print the prime numbers between 100-200
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions