ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

C Program for Bubble Sort or sorting using Arrays

Updated on December 21, 2012

Bubble Sorting is used in C programming to sort the numbers in increasing order . We just need to enter the required no. and this program will do rest of the work .

Following is the source code for Bubble Sorting program . You just need to copy it in your notepad and save it with the extension *.c or *.cpp . Then open the saved file with your compiler and run it .

int main()
int n, i, j, temp , a[100];
printf("Enter the total integers you want to enter (make it less than 100):\n");
printf("Enter the %d integer array elements:\n",n);
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
printf("The sorted numbers are:");

You may also want to read : C program for insertion sorting in arrays

This program has been written by me for maximum of 100 integers to sort out . If you feel like you want to increase the numbers for sorting , you may change the value of a[100] to a[xyz] where xyz is any integer value .

Further more , you can change the program according to your needs . :) Enjoy Programming .

P.S - The screenshot is the proof of a working program .


    0 of 8192 characters used
    Post Comment

    • profile image

      rahul 4 years ago


    • profile image 5 years ago

      its helpful to me

    • profile image

      ewane nelson 5 years ago

      i'll like to be like one of you someday. please teach me programming

    • techniche profile image

      techniche 6 years ago from Ambala, India

      Are you talking about this for loop ?? : for(j=0;j"less than"n-i-1;j++);

    • Davesworld profile image

      Davesworld 6 years ago from Cottage Grove, MN 55016

      Change you second "for" statement to:

      for(j=i;j "less than" n;j++) /* stupid comment box won't allow the inequality sign */

      You do not need to re-examine what you have already sorted.