#include
#include
void main()
{
int i,n,j,a[20];
void sort(int n,int a[]);
clrscr();
printf("\n\nENTER THE SIZE OF A THE ARRAY=");
scanf("%d",&n);
printf("\n\nENTER THE ELEMENTS=\n\n");
for(i=0;i< n;i++)
{
scanf("%d",&a[i]);
}
printf("\n\nARRAY BEFORE SORTING=\n");
for(i=0;i< n;i++)
{
printf("%d",a[i]);
printf("\n");
}
sort(n,a);
printf("\n\nARRAY AFTER SORTING\n");
for(i=0;i< n;i++)
{
printf("%d",a[i]);
printf("\n");
}
getch();
}
void sort(int n,int a[])
{
int i,j,temp,d;
for(i=0;i< n-1;i++)
for(j=i+1;j
if(a[i]>=a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
/*******************************************************************
OUTPUT
********************************************************************
ENTER THE SIZE OF A THE ARRAY=5
ENTER THE ELEMENTS=
2
1
4
3
5
ARRAY BEFORE SORTING=
2
1
4
3
5
ARRAY AFTER SORTING
1
2
3
4
5
*/
No comments:
Post a Comment