0% found this document useful (0 votes)
66 views1 page

Bubble Sort

This document describes the bubble sort algorithm for sorting an array of integers. It includes code to prompt the user to enter the size of the array and its elements, call the bubble_sort function to sort the array, and then print out the sorted array. The bubble_sort function uses a double for loop to iterate through the array, comparing adjacent elements and swapping them if out of order, to slowly "bubble" the largest values to the end of the array.

Uploaded by

satya_saraswat_1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views1 page

Bubble Sort

This document describes the bubble sort algorithm for sorting an array of integers. It includes code to prompt the user to enter the size of the array and its elements, call the bubble_sort function to sort the array, and then print out the sorted array. The bubble_sort function uses a double for loop to iterate through the array, comparing adjacent elements and swapping them if out of order, to slowly "bubble" the largest values to the end of the array.

Uploaded by

satya_saraswat_1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

www.eazynotes.

com

Gursharan Singh Tatla

Page No. 1

BUBBLE SORT
/***** Program to Sort an Array using Bubble Sort *****/

#include <stdio.h> void bubble_sort(); int a[50], n; main() { int i; printf("\nEnter size of an array: "); scanf("%d", &n); printf("\nEnter elements of an array:\n"); for(i=0; i<n; i++) scanf("%d", &a[i]); bubble_sort(); printf("\n\nAfter sorting:\n"); for(i=0; i<n; i++) printf("\n%d", a[i]); getch(); } void bubble_sort() { int j, k, temp; for(j=0; j<n; j++) for(k=0; k<(n-1)-j; k++) if(a[k] > a[k+1]) { temp = a[k]; a[k] = a[k+1]; a[k+1] = temp; } }

You might also like