Thread: More Prime Numbers

  1. #1
    Registered User
    Join Date
    Feb 2003

    Angry More Prime Numbers

    Ok, I've already posted a thread about a prime number program, and I got a lot of help, thanks to all the people who responded. Now, I need to write another program involving prime numbers. I need to write a program using the following function which determines if a number is prime, and print all of the prime numbers from 1 to 10,000. I know I should use an array, but I'm a rookie at C programming and I can't quite get it correctly. Thanks.


    ...printf( "%d are prime numbers.\n", x);

    return 0;

    //function checkprime definition

    int checkprime(num){

    int count, result;

    if((num == 0) || (num < 0) || (num == 1))
    return 2;

    for( count = 2; count < num; count ++ ){
    result = num % count;

    if (result == 0)

    return 0;


    return 1;

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Do you have to use an array (is it a requirement of your task)? Also, use code tags, every time you post code.

    Really if you've got your code to test for primes, you just need a loop for printing them. If you want to store them then you would use an array.
    Last edited by Azuth; 02-20-2003 at 10:10 PM.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    If you already have the code to calculate if a number is prime, just make it loop from 1 to 10000 and increment a counter each time the prime test passes.

    Modify your program so the array is that number in size, and then for the final product, make it assign that number to that slot in the array each time the test passes.

    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Ok, thanks, I think I can get it now.

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. prime numbers, counters, help!
    By vege^ in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2003, 04:32 PM
  4. Prime numbers
    By Lazy Student in forum C Programming
    Replies: 12
    Last Post: 05-14-2002, 05:53 AM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM