codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  should i use a multidimensional array???  dewjunkie at 01:39 on Friday, March 07, 2008
 

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;
}


  Re: should i use a multidimensional array???  e40pud at 08:29 on Friday, April 25, 2008
 

#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;
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
• Help with recursion { recursive helper function }
• mkdirs
• Re: Web Development Project
• ** Site Hacked ** javascript inserted...
• Losing background/text color when converting HTML to PDF
• hidden div block when displayed, displays at an offset of 200px only in IE 6..
• help - sketch
• Re: Perl Script - File Handling.
• Open a file from website


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008