Thread: using arrays to sort numbers

  1. #1

    Question using arrays to sort numbers

    i'm having problems with writing a program using arrays. i have to get the program to print out all the prime numbers up to 500. I'm using if/else statements and for loops but all i'm getting in return is 0 when i run the program. What am i doing wrong.

    Here's a sample of my work:
    for(digit=2; digit<=500; digit++)
    if(digit*2 != digit)

  2. #2
    Registered User
    Join Date
    Nov 2001
    it doesn't look like your doing it right cause you aren't assigning anything to the array. You will probably have to use a nested loop. Probably something of this sort

    int array = 500;
    for(int x = 0; x <= 500; x++)
    for(int y = 0; y <= 500; y++)

    do stuff here to figure out if it is prime then assign it to the array such as

    array[x] = prime number;

    then have a counter count up x everytime it finds a prime number


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  2. Replies: 4
    Last Post: 04-19-2005, 08:05 PM
  3. Sorting
    By vasanth in forum A Brief History of
    Replies: 12
    Last Post: 11-10-2003, 05:21 PM
  4. Bubble Sort with Arrays
    By 3kgt in forum C++ Programming
    Replies: 1
    Last Post: 04-09-2003, 01:48 AM
  5. arrays and random numbers
    By bruceness in forum C Programming
    Replies: 3
    Last Post: 10-23-2002, 09:36 PM