Thread: Printing Prime Numbers from 1 to 300.

  1. #16
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    @fgw_three

    Your program doesn't display the number 3...

    I guess if(i==number) is mandatory then..

  2. #17
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Here's something that worked..

    Idea based on that of fgw_three

    Code:
    for (number=2;number<=300;number++)
    	{
    		
    		for (div=2; div<number; div++)
    		{
    			if (number%div==0)
    			{
    				ifprime=0;
    				break;
    			}
    
    			ifprime=1;
    		}
    		
    		if (ifprime)
    		{
    			printf("\n%d", number);
    		}
    	}
    }


    I need to work more on this!!

  3. #18
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125
    Quote Originally Posted by duffmckagan
    @fgw_three

    Your program doesn't display the number 3...

    I guess if(i==number) is mandatory then..

    Like I said, I was stealing cycles from some real work.

    I never thought about Salem's point of no potential divisor being greater than the square root, and I never actually fired the program up and tested it...

    Hopefully it helped get you closer...
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking very large prime numbers
    By password in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2008, 12:26 PM
  2. Prime Numbers
    By EdSquareCat in forum C++ Programming
    Replies: 9
    Last Post: 05-29-2007, 05:54 PM
  3. prime numbers
    By Unregistered in forum C Programming
    Replies: 17
    Last Post: 08-20-2002, 08:57 PM
  4. Prime Numbers
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 09-24-2001, 07:11 PM
  5. prime numbers
    By maya in forum C Programming
    Replies: 1
    Last Post: 09-13-2001, 08:26 AM