#include<stdio.h>
#include<conio.h>
#define TURE 1
#define FLASE 0
void BubbleSort(int a[],int n)
{
int i,j;
int change;
int temp;
for(i=n-1,change=TURE;i>=1&&change;i--)
{
change=FLASE;
for(j=1;j<=i;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
change=TURE;
}
}
}
void Print(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
printf(" a[%d]=%d",i,a[i]);
}
main()
{
int a[100];
int i,n;
printf("/nInput the Length:/n");
scanf("%d",&n);
printf("/nInput the number:/n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("/nBefore:/n");
Print(a,n);
BubbleSort(a,n);
printf("/nAfter:/n");
Print(a,n);
getch();
printf("Press any key to continue...");
clrscr();
}
#include<conio.h>
#define TURE 1
#define FLASE 0
void BubbleSort(int a[],int n)
{
int i,j;
int change;
int temp;
for(i=n-1,change=TURE;i>=1&&change;i--)
{
change=FLASE;
for(j=1;j<=i;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
change=TURE;
}
}
}
void Print(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
printf(" a[%d]=%d",i,a[i]);
}
main()
{
int a[100];
int i,n;
printf("/nInput the Length:/n");
scanf("%d",&n);
printf("/nInput the number:/n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("/nBefore:/n");
Print(a,n);
BubbleSort(a,n);
printf("/nAfter:/n");
Print(a,n);
getch();
printf("Press any key to continue...");
clrscr();
}