0% found this document useful (0 votes)
38 views

Selection Sort DSC

This program implements selection sort to arrange a list of integers in ascending order. It takes user input for the number of elements and the list of integers. It then calls the selectionsort function, which iterates through the list, finds the minimum element in each pass, swaps it with the first element, and prints out the sorted list.

Uploaded by

gouse1210
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Selection Sort DSC

This program implements selection sort to arrange a list of integers in ascending order. It takes user input for the number of elements and the list of integers. It then calls the selectionsort function, which iterates through the list, finds the minimum element in each pass, swaps it with the first element, and prints out the sorted list.

Uploaded by

gouse1210
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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