/* BUBBLE SORT */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,temp;
clrscr();
printf("\n\t\tINPUT:");
printf("\n\t\t------");
printf("\n\t\tEnter the number of elements: ");
scanf("%d",&n);
printf("\n\t\tEnter the elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
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\t\tOUTPUT:");
printf("\n\t\t-------");
printf("\n\t\tAfter sorting the elements are:");
for(i=0;i<n;i++)
{
printf("\n\t\t\t\t%d",a[i]);
}
getch();
}
INPUT:
------
Enter the number of elements: 5
Enter the elements:
70
56
23
67
89
OUTPUT:
-------
After sorting the elements are:
23
56
67
70
89
No comments:
Post a Comment