C program to sort array in ascending order

Program in the C programming language to sort all the elements in the array in the ascending order. This programs uses the bubble sort method to sort the numbers in ascending order.

Definition Bubble Sort– Bubble sort is a simple sorting technique in which passes are used and after each pass larger no. obtains it’s sorted position. To sort the elements ‘n-1‘ passes are used where n is the total number of elements.

/* C program to arrange or sort the array in the ascending order */
void main()
     int ar[100],j,n,i,tmp;
     printf(" Enter the size of the array \t");
     printf("Now enter the elements in the array \t");
     printf("\n Array is - ");
           printf("\t %d",ar[i]);
     printf("\n\n Array in the ascending order is - \n");
           printf("\t %d",ar[i]);

Input –
Enter the size of the array – 5
Array is – 23     65    10    45    34
Output –
Array in the Ascending order is – 10    23    34    45    65


  1. Umar says:

    Make it abit easy and understandable

  2. nikita says:

    make it easy study material for students…

  3. Vicky says:

    thanks….i was in need of this program….i got it now

  4. ngoyi says:

    Hello ! I am, John paul Dengo. and i need to learn morrow about C & C++. Tha’s why i’m interesting to you.

  5. dharani says:

    thanks i got the prgm easily frm this site

  6. tarzan says:

    there is a bug
    for(j=0;j<n-i;j++) === wrong


    • ASHWIN KAIN says:

      well, n-1 is wrong there’s no bug, prog. is simple and easy.

    • khwaja says:

      for n-i its printing -2 garbage value at the begining in case of static arrays …for dynamic arrays its fine..
      for static n-1 is correct.

      • fahad says:

        really helpful 4 my wife febin

    • Alyssa says:

      for(j=0;j<n-i;j++) there is a bug, because when j=n-i-1, which is the maximum value of j, j+1=n-i and there is no value for ar[j+1]. In this case ar[j+1] will be a random number chosed by the computer. The correct answer should be for(j=0;jar[j+1]) into if(ar[j]<ar[j+1]) and then we will find the bug.

  7. Dinesh Kiran says:


  8. Sherin says:

    I’m little satisfied on searching wth this site

  9. saadat says:

    don’t worry i will gave’s part and how you can implement you’r program by using c++ i’m also a student and i have alred implement a simple program achuly i need to know more about c++

  10. Parashuram says:

    Please give me programs on an array daily one to my ewail id. Thanks

  11. falesh kumar says:

    Thank you for help

  12. priyanka says:

    this program is a grt help to me

    • priyanka says:

      thank u

      • Henrietta says:

        Stands back from the keyboard in amntemeaz! Thanks!

  13. santosh ojha says:

    give atleast one question answer and i,e.,complete

  14. Harsha says:

    iz really helpful……….

  15. aviketh says:

    soooooooooo helpful……….

  16. fahad says:

    Itz very helpful……….

  17. http://www.petasse.sx says:

    Εncore un sublime article : j’en discuterai dans la semaine avec mes voisins

  18. Aimfosys says:

    Very Helpful article while array size is user defined

  19. paras rai says:


    but i wnt 2 knw y we use j loop??


  1. C++ Program Ascending Order Using Array - [...] PDF File Name: C program to sort array in ascending order Source: www.studystreet.com » DOWNLOAD « …

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This