Thread: array in ascending order

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    63

    array in ascending order

    hi
    could u plz help me out with this array problem...in which i have to print "array elements in ascending order"....while compilation there is no error but when i run the code it shows the output as -- 24768, which is very weird. i have wriiten the code like this:::


    #include<stdio.h>
    #include<conio.h>
    int main(void)
    {
    int a[10],temp,i,j;
    clrscr();
    printf("ENTER ARRAY ELELMENTS:");
    for(i=0;i<10;i++)
    scanf("%d",&a[i]);
    fflush(stdin);
    for(i=0;i<10;i++)
    {
    for(j=j+1;j<10;j++)
    {
    if(a[i]>a[i+1])
    {
    temp=a[i];
    a[i]=a[i+1];
    a[i+1]=temp;
    }
    }
    }
    printf("SORTED ARRAY IS:");
    fflush(stdout);
    for(i=0;i<10;i++)
    printf("%d",a[i]);
    fflush(stdout);
    getch();
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    63
    can any 1 help me out with this code//////////plz
    i don't know how to make this work..........?

    plz help me out guys...........

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Once you edit your post to include CODE tags, read all about them here:
    http://cboard.cprogramming.com/showthread.php?t=25765
    Code:
    //Like this
    Which xErath mentioned in your last thread which is the same as this one (When the topics are this similar, keep posting in the same thread, there's no point in wasting room on the board with the same topic).

    As I was saying, once you do that, you'll get more help.

    Note: You still haven't given "j" an initial value along with many many more of Prelude's and Scribbler's suggestions in your last thread. It would be a good idea to read all the replies there more thoroughly and look at the differences between your code and Prelude's example.

  4. #4
    dont use

    Code:
    fflush(stdin);

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    How about you stop spamming the board, and stick to one thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Outputting an Array of 5 Numbers in Order
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 06-30-2009, 07:20 AM
  2. Problem with ascending order Program
    By cashmerelc in forum C Programming
    Replies: 4
    Last Post: 09-21-2007, 05:36 PM
  3. organize values of array in ascending order
    By incognito in forum C++ Programming
    Replies: 4
    Last Post: 11-08-2003, 10:55 PM
  4. reverse the order of an array
    By dustyd in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2003, 11:14 AM
  5. read into array and spit out in reverse order
    By steven in forum C Programming
    Replies: 4
    Last Post: 09-07-2001, 02:27 PM