0% found this document useful (0 votes)
36 views4 pages

Sorting in C

The document introduces sorting as a technique to arrange elements in a specific order, highlighting bubble sort as a method that compares and swaps adjacent elements. It includes a C programming example that demonstrates the implementation of bubble sort to sort an array of integers. The code prompts the user for the number of elements and outputs the sorted array.
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)
36 views4 pages

Sorting in C

The document introduces sorting as a technique to arrange elements in a specific order, highlighting bubble sort as a method that compares and swaps adjacent elements. It includes a C programming example that demonstrates the implementation of bubble sort to sort an array of integers. The code prompts the user for the number of elements and outputs the sorted array.
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/ 4

SORTING

1
INTRODUCTION
 Sorting is a technique used to arrange
elements of an array/list in a specific order
 There are various sorting algorithms that
can be used to complete this operation.
 Bubble sort is one of the sorting
technique that compares two adjacent
elements and swaps them until they are in
the intended order.
2
3
#include <stdio.h>
int main() {
int arr[] = {29, 10, 14, 37, 13};
int n, i, j, temp;
printf(“Enter the number of elements”);
scanf(“%d”,&n);
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;
}
}
}
printf("Sorted array: ");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}

You might also like