-: Bubble Sort :-
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n,a[10],temp;
clrscr();
printf("\nEnter the number of terms:");
scanf("%d",&n);
printf("\n Enter the elements:");
for(i=0;i<n;i++)
{
printf("\n a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[j]<=a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
for(i=0;i<n;i++)
printf("\n %d",a[i]);
getch();
}
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n,a[10],temp;
clrscr();
printf("\nEnter the number of terms:");
scanf("%d",&n);
printf("\n Enter the elements:");
for(i=0;i<n;i++)
{
printf("\n a[%d]=",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[j]<=a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
for(i=0;i<n;i++)
printf("\n %d",a[i]);
getch();
}
No comments:
Post a Comment