0% found this document useful (0 votes)
14 views1 page

C Code for Selection Sort Algorithm

The document contains a C program that implements the selection sort algorithm to sort an array of integers. It defines functions for sorting and swapping elements, takes user input for the size and elements of the array, and outputs the sorted array. The program is structured with a main function that orchestrates the sorting process.

Uploaded by

Ravan bhoye
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

C Code for Selection Sort Algorithm

The document contains a C program that implements the selection sort algorithm to sort an array of integers. It defines functions for sorting and swapping elements, takes user input for the size and elements of the array, and outputs the sorted array. The program is structured with a main function that orchestrates the sorting process.

Uploaded by

Ravan bhoye
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Selection Sort

#include <stdio.h>
void selectionSort(int arr[], int size);
void swap(int *a, int *b);

void selectionSort(int arr[], int size)


{
int i, j;
for (i = 0 ; i < size;i++)
{
for (j = i ; j < size; j++)
{
if (arr[i] > arr[j])
swap(&arr[i], &arr[j]);
}
}
}

void swap(int *a, int *b)


{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

int main()
{
int array[10], i, size;
printf("How many numbers you want to sort: ");
scanf("%d", &size);
printf("\n\tEnter %d numbers\t", size);
printf("\n");
for (i = 0; i < size; i++)
scanf("%d", &array[i]);
selectionSort(array, size);
printf("\n\tSorted array is ");
for (i = 0; i < size;i++)
printf(" %d ", array[i]);
return 0;
}

You might also like