Bubble sort program in C

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

Here is the program to sort the given integer in ascending order using bubble sort method. Please find the pictorial tutor of the bubble sorting.

Logic :  The entered integers are stored in the array A. Here, to sort the data in ascending order, any number is compared with the next numbers for orderliness. i.e. first element A[0] is compared with the second  element A[1]. If forth is greater than the prior element then swapping them, else no change. Then second element is compared with third element, and procedure is continued. Hence, after the first iteration of the outer for loop, largest element is placed at the end of the array. In the second iteration, the comparisons are made till the last but one position and now second largest element is placed at the last but one position. The procedure is traced till the array length.

If we complement the if condition in this program, it will give out the sorted array in descending order. Sorting can also be done in other methods, like selection sorting and insertion sorting, which follows in the next pages.

Bubble sort Image Demo
Bubble sort Image Demo

Here is the C program to sort the numbers using Bubble sort

#include
void main()
{
	int A[20], N, Temp, i, j;
	clrscr();
	printf(“\n\n\t ENTER THE NUMBER OF TERMS…:);
	scanf(%d”,&N);
	printf(“\n\t ENTER THE ELEMENTS OF THE ARRAY…:);
	for(i=0; i<N; i++)
	{
		scanf(“\n\t\t%d”, &A[i]);
	}
	for(i=0; i<N-1; i++)
		for(j=0; j<N-i;j++)
			if(A[j]>A[j+1])
			{
				Temp = A[j];
				A[j] = A[j+1];
				A[j+1] = Temp;
			}
	printf(“\n\tTHE ASCENDING ORDER LIST IS…:\n”);
	for(i=0; i<N; i++)
		printf(“\n\t\t\t%d”,A[i]);
	getch();
}

Download exe and source code here.

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

72 Responses to “Bubble sort program in C”

  1. thanks for uploading program….it helps me in the exam….just copy paste dude….

    Reply
  2. Gold is one of the traditional precious metals used for wedding jewelry.

    So how can the happy couple reduce the unrivalled stress levels that come with such an predominant event in their lives.
    As a wedding is a one-time event, the photographer must be prepared for the unexpected.

    Reply
  3. The equipment itself is not really particularly expensive these times,
    so leasing can cost considerably more in the medium-to-long term.

    You can know all the ins and outs of business and can run a restaurant without fail; but would you know the first thing about installing the kitchen grills.
    Two: Increase in income – When you are able to increase your
    traffic to the business, you will easily be able to also increase
    your income.

    Reply
  4. Starting a small business with no money may sound impossible but there are ways to kick off a very profitable
    business without ever spending a single dime of your own money.
    You can know all the ins and outs of business and can run a restaurant without fail;
    but would you know the first thing about installing the
    kitchen grills. Clients do not look no matter whether you’ve a small or big budgeted communication service.

    Reply
  5. The equipment itself is not really particularly expensive these
    times, so leasing can cost considerably more in the medium-to-long term.
    When job offers do come and I’ll admit, some companies may fear hiring you because they
    fear a former owner being an employee, negotiate the best salary you can along with the best benefits you can for
    you and your family. What you give away doesn’t have to be costly, but it must be valuable.

    Reply
  6. The equipment itself is not really particularly expensive these times,
    so leasing can cost considerably more in the medium-to-long term.
    Without enough traffic, you will never have enough
    customers and this means you won’t be making enough money.
    For clients, you can target neighborhoods, communities
    or even companies.

    Reply
  7. The following are the benefits that you have to be aware of
    the most. You can know all the ins and outs of business and can run a
    restaurant without fail; but would you know the first thing about installing the kitchen grills.
    Two: Increase in income – When you are able to increase your traffic to the business, you will easily be able to also
    increase your income.

    Reply
  8. If you’re educated (or seeking an education) you will probably find a ton of opportunity in a
    small town. As with everything else, it is only the mindset of the entrepreneur that dictates the success
    and failure of a company. For clients, you can target neighborhoods,
    communities or even companies.

    Reply
  9. Or, perhaps you’re one of those students who desires a challenge, or even a
    good addition to your résumé for Grad school.
    You can know all the ins and outs of business and can run a restaurant without fail; but
    would you know the first thing about installing the kitchen grills.
    Typically, this works well if we are involved in a solid networking and we reciprocate, by referring clients to those
    other businesses.

    Reply
  10. Yet, there are grants that are made for equipment and
    training. You can know all the ins and outs of business and
    can run a restaurant without fail; but would you know the first thing about installing the
    kitchen grills. Clients do not look no matter whether you’ve a small or big
    budgeted communication service.

    Reply

Leave a Reply