Thread: Prime odd numbers

  1. #1
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949

    Prime odd numbers

    What would an easy way to detect odd prime numbers? Thanks!
    Do not make direct eye contact with me.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What would an easy way to detect odd prime numbers?
    http://www.gdargaud.net/Humor/OddPrime.html

    But seriously, this may help us both (you since it has code, and me since I don't have to post any):
    http://www.newdream.net/~sage/old/numbers/primeodd.htm

    -Prelude
    My best code is written with the delete key.

  3. #3
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    can anyone post any simple code, or explain the one Prelde gave me? Thanks!
    Do not make direct eye contact with me.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Basaically, I'm just loking for a function to write out all primes below a specified number.

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Here's some pseudocode to check primality:
    Code:
    let the number to be checked be referred to as x
    for each odd number(n) greater than 1 and less than the square root of x
    	if x is divisible by n then the number is not prime
    repeat
    if x wasn't divisble by any values of n, it's prime
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    I'm new w/c, how would i d this?
    Do not make direct eye contact with me.

  7. #7
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949

    Unhappy

    Cant think of anything that works...

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Lurker
    Cant think of anything that works...
    This would be your first line:
    #include <stdio.h>

    Now come on, show a bit of effort. Post again when you have some code.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Ok, heres what i have so far, only displays odd numbers besides 1 right now:

    Code:
    #include <stdio.h>
    
    int main(void) {
    	register int i, n;
    	for(i=0; i < 2001; i++) {
    		if((i % 2 == 0) || (i == 2) || (i == 1)) continue;
    		printf("%d   ", i);
    	}
    	getchar();
    	return 0;
    }
    Do not make direct eye contact with me.

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>only displays odd numbers besides 1 right now
    How many even prime numbers do you know of?

    Use XSquared's pseudo code to help build your C code.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    >>Use Prelude's pseudo code to help build your C code.
    I se XSquared pseudo code

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>I se XSquared pseudo code
    It's been a long day
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>Use Prelude's pseudo code to help build your C code

    Don't you mean my pseudocode?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Prime odd numbers

    Originally posted by Lurker
    What would an easy way to detect odd prime numbers? Thanks!
    All prime numbers are odd. If it's an even number, it's not prime.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Don't you mean my pseudocode?
    That was my fault, my brain had a GPF, and I put the wrong name by mistake. Like I said, long day...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Replies: 18
    Last Post: 11-04-2005, 02:41 PM
  3. Help with prime numbers
    By Clean Killa in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2002, 04:42 PM
  4. Prime Wonder
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-07-2002, 11:49 PM
  5. adding odd numbers
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 09-06-2001, 01:44 PM