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

Experiment 7

Uploaded by

adarsh23169049
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

Experiment 7

Uploaded by

adarsh23169049
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>

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

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

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

// Swap if the current element is smaller than the next element

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

int temp = arr[j];

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

arr[j + 1] = temp;

int main() {

int n;

printf("Enter the number of elements: ");

scanf("%d", &n);

int arr[n];

printf("Enter %d integers:\n", n);

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

scanf("%d", &arr[i]);

bubbleSort(arr, n);

printf("Array in decreasing order:\n");

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

printf("%d ", arr[i]);

}
printf("\n");

return 0;

INPUTS :

Enter the number of elements: 5

Enter 5 integers:

10 3 15 7 1

OUTPUTS :

Array in decreasing order:

15 10 7 3 1

You might also like