0% found this document useful (0 votes)
6 views2 pages

DS12

The document contains a C program that implements the Bubble Sort algorithm to sort an array of integers. It defines a function to perform the sorting and another function to print the sorted array. The main function initializes an array, calls the sorting function, and then prints the sorted result.

Uploaded by

adeshkarde
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)
6 views2 pages

DS12

The document contains a C program that implements the Bubble Sort algorithm to sort an array of integers. It defines a function to perform the sorting and another function to print the sorted array. The main function initializes an array, calls the sorting function, and then prints the sorted result.

Uploaded by

adeshkarde
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
You are on page 1/ 2

#include <stdio.

h>

// Function to perform Bubble Sort

void bubbleSort(int arr[], int n) {

for (int i = 0; i < n - 1; i++) {

for (int j = 0; j < n - i - 1; j++) {

if (arr[j] > arr[j + 1]) {

// Swap arr[j] and arr[j+1]

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

// Function to print the array

void printArray(int arr[], int n) {

printf("Sorted array: ");

for (int i = 0; i < n; 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]);

bubbleSort(arr, n);

printArray(arr, n);

return 0;

OUTPUT:

Sorted array: 11 12 22 25 34 64 90

You might also like