*/
#include
#include
void main()
{
int a[20],i,j,n,small,p,temp,e;
clrscr();
printf("\n\nENTER THE NO OF ELEMENTS=");
scanf("%d",&n);
printf("\n\nENTER THE ELEMENTS IN AN ARRAY=");
for(i=0;i< n;i++)
{
scanf("%d",&a[i]);
printf("\n\n");
}
for(i=0;i< n;i++)
{ small=a[i];
for(j=i;j< n;j++)
{if (a[j]< small)
{small=a[j];
p=j;
temp=a[i];
a[i]=small;
a[p]=temp;
}}}
printf("\n\nAFTER SORTING VALUES ARE=\n\n");
for(i=0;i< n;i++)
{
printf("\n\n");
printf("%d",a[i]);
}
getch();
}
/******************************************************************
OUTPUT
******************************************************************
ENTER THE NO OF ELEMENTS=5
ENTER THE ELEMENTS IN AN ARRAY=2
1
3
5
4
AFTER SORTING VALUES ARE=
1
2
3
4
5
*/
No comments:
Post a Comment