/*write a c program to sort array element using selection sort method*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,temp=0;
clrscr();
printf("how many number you want to enter:-");
scanf("%d",&n);
printf("\nenter number for an array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nthe sorted array is:-\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}
/*how many number you want to enter:-4
enter number for an array7
8
5
8
the sorted array is:-
5
7
8
8
*/
No comments:
Post a Comment