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

Bubble Sort Algorithm in C

The document contains a C program that implements the bubble sort algorithm to sort an array of integers. It defines functions to perform the sorting and to print the array before and after sorting. The output demonstrates the original and sorted arrays.

Uploaded by

gtprogrammzz
Copyright
© All Rights Reserved
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)
3 views1 page

Bubble Sort Algorithm in C

The document contains a C program that implements the bubble sort algorithm to sort an array of integers. It defines functions to perform the sorting and to print the array before and after sorting. The output demonstrates the original and sorted arrays.

Uploaded by

gtprogrammzz
Copyright
© All Rights Reserved
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

PROGRAM

#include <stdio.h>
void bubbleSort(int arr[], int n)
{
int i, j, temp;
for (i = 0; i < n - 1; i++)
{
​ for (j = 0; j < n - i - 1; j++)
{
​ if (arr[j] > arr[j + 1])
{
​ ​ temp = arr[j];
​ ​ arr[j] = arr[j + 1];
​ ​ arr[j + 1] = temp;
​ }
​ }
}
}
void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
int main()
{
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = sizeof(arr) / sizeof(arr[0]);
printf("Original array: ");
printArray(arr, n);
bubbleSort(arr, n);
printf("Sorted array: ");
printArray(arr, n);

return 0;
}

OUTPUT:
Original array: 64 34 25 12 22 11 90
Sorted array: 11 12 22 25 34 64 90

You might also like