Welcome to Dream.In.Code
Become a Java Expert!

Join 149,598 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,898 people online right now. Registration is fast and FREE... Join Now!




Sieve of Eratosthenes - HELP!

 
Reply to this topicStart new topic

Sieve of Eratosthenes - HELP!, I need to create a program in Java

shycdngurl
17 Oct, 2007 - 11:59 AM
Post #1

New D.I.C Head
*

Joined: 17 Oct, 2007
Posts: 1


My Contributions
This is what I have so far....
CODE

main()
{
     int num[100], i, j;
    
     for(i=0;i<=99;i++)     /*Fill num with the first 100 numbers*/
          num[i]=i+1;
    
     for(i=1;i<=99;i++)
     {
          if(num[i]!=0)
          {
               for(j=(i+1);j<=99;j++)
               {
                    if(num[j]!=0)
                    {
                         if((num[j]%num[i])==0)     /*check if num[j]*/
                         num[j]=0;                    /*is a multiple of num[i]*/
                                                       /*if it is a multiple then set it to 0*/
                    }
               }
          }
     }

     for(i=0;i<=99;i++)
     {
          if(num[i]!=0)                    /*Print all non zero numbers (prime numbers)*/
               printf("\n%d",num[i]);
     }
}


But, not sure why it is not working??? Maybe I have it in the wrong spot....wrong tag somewhere.....or maybe its wrong all together.

Help me.

~Added Code Tags - skyhawk133
User is offlineProfile CardPM
+Quote Post

girasquid
RE: Sieve Of Eratosthenes - HELP!
17 Oct, 2007 - 12:36 PM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,294



Thanked: 18 times
Dream Kudos: 725
My Contributions
I think you might have the wrong forum.
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Sieve Of Eratosthenes - HELP!
17 Oct, 2007 - 01:34 PM
Post #3

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,262



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Moving to Java.

Adding [code] tags.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:35PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month