I am working on homework, and been doing this assignment with absolutely no luck, i am in need of major help.
This is the assignment. Using an array, initialize all elements in the array to 1. Starting with array subscript 2, every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose subscript is a multiple of the subscript for the element with value 1. all elements beyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6, 8, 10, etc.);
this is my code, i have initialized all elements in the aray to 1. I need MAJOR help with a formula to determine if its prime, and set everything else to a 0. I have been working on this one part for 3 days and i finally gave in and need help... Any help is really appiciated!!!
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void prime_num(int);
const unsigned W = 10;
int main()
{
const unsigned arraySize = 5000;
int a[arraySize];
unsigned b;
unsigned c;
unsigned d;
cout<<"This program is programming assignemnt #5."<<endl;
cout<<"THE SIEVE OF ERATOSTHENES."<<endl;
cout<<"By Jeremy Rice of CSCI 111."<<endl;
for (int i = 2; i < arraySize; i++)
{
a[i] = 1;
}
for (int j =2; j < b; j++)
system("pause");
return 0;
}