Thread: Array question.

  1. #1
    Unregistered
    Guest

    Question Array question.

    Sorry newbie here! Pls bear...

    Yeah I want the user to enter 10 digits, stored in arrays. Arary is then sorted in descending order(using functions is possible). Then using another function display the sorted array.

  2. #2
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284

    Re: Array question.

    Originally posted by Unregistered
    Sorry newbie here! Pls bear...
    I wont

  3. #3
    Addicted to the Internet netboy's Avatar
    Join Date
    Dec 2001
    Posts
    158
    I think it's a better idea to show what you have done... The way you are asking is like asking someone to do homework for you...

    You show what you have done and sure the ppl here will not hesitate to help you solve the problem(s) you are facing...
    It's unfulfilled dreams that keep you alive.

    //netboy

  4. #4
    Unregistered
    Guest

    Talking

    Aahhhhh sh|t! The program crashed!

    Ggrrr... I'd post up, what I have done as soon as I re-type it. My problem was the sorting in descending order part. I don't get how to do it(I tried). I thought it would've worked, but since it crashed I guess not.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Have you tried qsort?

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

  6. #6
    Addicted to the Internet netboy's Avatar
    Join Date
    Dec 2001
    Posts
    158
    How about sorting is the normal way (acsending) and then printf it the other way round so that it will be displayed in desending order?
    It's unfulfilled dreams that keep you alive.

    //netboy

  7. #7
    Unregistered
    Guest
    Code:
    .
    .
    .
     for(counter = 1; counter <=10; ++counter)
     { printf("\nEnter 10 numbers: ");
        scanf("%d", &a[counter]);
     }
    .
    I am not sure if even this works, but I would appreciate it if someone would flame me to the right direction... IF necessary.
    Also I don't even know how to sort an array(ascendingly) so I wouldn't know how to follow netboy's method.
    Prelude, I am required to use a function to sort it(if it's at all possible) and try not to involve pointers, so your suggested method I'm gonna keep as a last resort. Anyway, I did a little search on some C sites and came up with the below code for sorting.

    Code:
    /* bubble sort the array */
    for (x=0; x < MAX-1; x++)
        for (y=0; y < MAX-x-1; y++)
            if (a[y] > a[y+1])
            {
                t=a[y];
                a[y]=a[y+1];
                a[y+1]=t;
            }
    /* print sorted array */
    printf("--------------------\n");
    for (i=0; i < MAX; i++)
    printf("%d\n",a[i]);
    I don't really know how to implement it seeing as how I won't know the MAX value either.

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >I don't really know how to implement it seeing as how I won't know the MAX value either.
    MAX is the number of elements in the array (in your cause 10 I presume).

    In the bubble sort code, "a" is the array, which just happens to have the same name as your array
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    why dont you replace MAX by 10 and try to understand what the code is doing ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM