/************************Bubble Sorting**************************/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],n,i,j,t;
clrscr();
printf("\n\n Enter integer value for total no.s of elements to be sorted: ");
scanf("%d",&n);
for( i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=n-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("\n\n Finally sorted array is: ");
for( i=0;i<=n-1;i++)
printf("\n%d",a[i]);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],n,i,j,t;
clrscr();
printf("\n\n Enter integer value for total no.s of elements to be sorted: ");
scanf("%d",&n);
for( i=0;i<=n-1;i++)
scanf("%d",&a[i]);
for(i=n-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("\n\n Finally sorted array is: ");
for( i=0;i<=n-1;i++)
printf("\n%d",a[i]);
getch();
}
No comments:
Post a Comment