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

Test Case

The document provides a C program that implements the Bubble Sort algorithm to sort a given set of N numbers. It prompts the user to input the size of the array and the numbers, displays the unsorted array, performs the sorting, and finally prints the sorted array. The program utilizes nested loops to compare and swap elements to achieve the sorted order.

Uploaded by

mohitek894
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 views1 page

Test Case

The document provides a C program that implements the Bubble Sort algorithm to sort a given set of N numbers. It prompts the user to input the size of the array and the numbers, displays the unsorted array, performs the sorting, and finally prints the sorted array. The program utilizes nested loops to compare and swap elements to achieve the sorted order.

Uploaded by

mohitek894
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/ 1

L8 - Sort the given set of N numbers using Bubble sort

/*L8 – Bubble Sort */


#include <stdio.h>
int main()
{
int n, a[20], i, j, temp;
printf("Bubble Sort: \n");
printf("Enter size of array: ");
scanf("%d", &n);
printf("Enter %d numbers one by one: \n", n);
for (i=0; i<n; i++)
scanf("%d", &a[i]);
printf("Array before sort: ");
for (i = 0; i < n; i++)
printf("%d ", a[i]);

/* Bubble sort begins */


for (i = 0; i < n - 1; i++)
for (j = 0; j < (n - i - 1); j++)
if (a[j] > a[j + 1])
{
temp = a[ j ];
a[ j ] = a[ j + 1];
a[ j + 1] = temp;
}

printf("\n Sorted array: ");


for (i = 0; i < n; i++)
printf("%d ", a[i]);
}

Test Case:

You might also like