/* C code for the implementation of Bubble Sort*/
#include<stdio.h>
int
main()
{
int
n, i, a[50], temp;
printf(“Enter
n”);
scanf(“%d’,&n);
printf(“Enter
%d values”,n);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
/*
Code for 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
Sorted Values are as follow\n”);
for(i=0;i<n;i++)
{
printf(“\n%d”,a[i]);
}
return(0);
}
No comments:
Post a Comment