Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The goal of following program is to print out the prime numbers between 2 and 10

ID: 3669768 • Letter: T

Question

The goal of following program is to print out the prime numbers between 2 and 100, inclusively, although it contains missing code. Specifically, you are to add the Boolean expression to control the while loop so that it checks all numbers between 2 and 100, inclusively (be sure to modify your control variable inside your while loop so that you do not get an infinite loop). Then, inside your while loop, add if-else statements as indicated and print out all of the prime numbers between 2 and 100, inclusively.

Explanation / Answer

Try this one

#include <cstdio>
#include <bitset>
#include <cmath>

using namespace std;

int main()
{
bitset<1000010> viz;
viz.reset();

int n;
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);

scanf("%d", &n);

if(n == 2)
{
  printf("%d ", 0);
  return 0;
}

int i;

if(viz[500000])
  ;
  
for(i = 1; i <= (sqrt((double)n) / 2); i++)
{
  if(!viz[i])
  {
   int x = ((i << 1) + 1) * ((i << 1) + 1);
   
   while(x < n && x > 0)
   {
    if(x % 2) viz[x >> 1] = 1;
    x += (i << 1) + 1;
   }
  }
  
}

printf("%d ", n - viz.count() - (n-1)/2 - 1);

return 0;
}

or else u can try this one also

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote