|
Hey all! I am a c++ noob.
I have the assignment of reproducing the Sieve of Erathostenes(which determines the prime #s in an interval). My code will give me all the prime #s up to 1033 like I need. My problem is I can't figure out how to format it how I want. I want to output 10 prime numbers on every line.
Since I am using arrays I thought that I might want to create a multidimensional array?
How would I accomplish this? I have been trying for quite some time and can't figure it out.
This is my code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int pArray[1050];
for (int i = 2;i <= 1033; i++)
{
pArray = i;
if (i > 2 && i%2 == 0)
cout << "";
else if (i > 3 && i%3 == 0)
cout << "";
else if (i > 5 && i%5 == 0)
cout << "";
else
cout << setw(4)<< pArray <<" ";
}
cout << "\n";
system("PAUSE");
return 0;
}
|
|
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int j = 1;
for (int i = 2;i <= 1033; i++)
{
if (i > 2 && i%2 == 0)
cout << "";
else if (i > 3 && i%3 == 0)
cout << "";
else if (i > 5 && i%5 == 0)
cout << "";
else if (j%10 == 0)
{
cout << setw(4)<< i << endl;
j++;
}
else
{
cout << setw(4)<< i << " ";
j++;
}
}
cout << "\n";
system("PAUSE");
return 0;
}
|
|
|
|
|
|
|
// |