You are on page 1of 1

Name of the Program:week8b

Week 8b:Write C programs for implementing the following sorting methods to arrange a list of
integers inascending order:b) Selection sort
a[i]=a[min];
#include<stdio.h>
a[min]=temp;
void selectionsort(int a[20],int n);/*function
}
decleration*/
printf("\n sorted arrays\n");
void main()
for(i=0;i<n;i++)
{/*begining main*/
printf("\n%d",a[i]);
int n,a[20],i;/*variables*/
} /*end of the program
printf("enter the no of elements \n");
Output:
scanf("%d",&n);
$ ./a.out
printf("enter the elements \n");
enter the no of elements
for(i=0;i<n;i++)/*for taking values*/
6
scanf("%d",&a[i]);
enter the elements
selectionsort(a,n);/*calling function*/
78
}
56
void selectionsort(int a[20],int n)/*function
45
definition*/
58
{
89
int i,j,k,min,temp;
103
for(i=0;i<n-1;i++)/*logic*/
{
sorted array
min=i;
for(j=i+1;j<n;j++)
45
{
56
if(a[min]>a[j])
58
min=j;
78
}
89
temp=a[i];
103[13r21a0507@mysqldbserver week8]$

You might also like