Ok, i have this program
It determines if the number entered is a prime or not.
I did that, posted it, and now i need to do this:
Determine and print the prime numbers between a user-specified lower bound and user-specified upper bound.

Read all through my text and browsed all over the net... How exactly would you do that? Is there a certain function?
This isnt homework, well, its extra credit while over break.

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;


const unsigned W = 10;


int main(int argc, char *argv[])
{
   const unsigned long arraySize = 1000000;
   bool a[arraySize];
   unsigned long b, x;
   unsigned long counter = 0;
   unsigned long primes = 0;
   char z;

cout<<"This program is programming assignemnt #5."<<endl;
cout<<"THE SIEVE OF ERATOSTHENES."<<endl;
cout<<"By Jeremy Rice of CSCI 111."<<endl;


//Initializing elements to 1 
        
for (int i = 0; i < arraySize; i++)             
{
   a[i] = 1;
}       
// For array subscript 2, all elements beyond 2 in the array that
// are multiples of 2 will be set to zero ; for array subscript 3, 
// all elements beyond 3 in the array that 
// are multiples of 3 will be set to zero


for (int i = 2; i * i < arraySize; i++)
    if (a[i])
       for (int j = i + i; j < arraySize; j += i)
           a[j] = 0;      
                                           

// print all subscripts set to 1
do
{
 cout<<"Prime > ";
 cin>>b;
        if (a[b] == 1)
           {
            cout<<b<<" is a prime number."<<endl;
           }
            else if
                 (a[b] == 0)
            cout<<"This is not a prime number."<<endl;
 cout<<"Check another number? (Y/N)"<<endl;         
  cin>>z;
} while((z == 'y')||(z == 'Y'));




system("pause");
return 0;
}

just create a loop that counts from lower_bounds to upper_bounds, and check the value of the loop counter if it is a prime number or not.

This article has been dead for over six months. Start a new discussion instead.