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

7) Sort The Given Set of N Numbers Using Bubble Sort

Uploaded by

shreeumaluti
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)
21 views2 pages

7) Sort The Given Set of N Numbers Using Bubble Sort

Uploaded by

shreeumaluti
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

7) Sort the given set of n numbers using bubble sort.

/*To sort n values using bubble sort in ascending order*/


#include<stdio.h>
int main()
{
int n, a[20], i, j, temp;

/* Accepting input */
printf("Hown many numbers?\n");
scanf("%d",&n);
printf("Enter %d numbers: \n",n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}

printf("Numbers before sorting: \n");


for(i=0; i<n; i++)
{
printf("%d ",a[i]);
}
/*Bubble sort begins*/
for(i=0; i<n; 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 After sorting: \n");
for(i=0; i<n; i++)
{
printf("%3d",a[i]);
}
}

You might also like