Selection Sort Example In C

*
Selection sort in C to lớn sort numbers of an array in ascending order. With a little modification, it arranges numbers in descending order.

Bạn đang xem: Selection sort example in c

Selection sort algorithm (for ascending order)

Find the minimum element again in the remaining array<2, n> và swap it with the element at 2nd position, now we have two elements at their correct positions.We have to bởi this n-1 times to lớn sort the array.

Xem thêm: Điểm Danh Top 20 Bộ Phim Lẻ Hay 2021: Sát Thủ Và Gái Đẹp, Sát Thủ Hồi Sinh


#include

int main() int array<100>, n, c, d, position, t;

printf("Enter number of elements "); scanf("%d", &n);

printf("Enter %d integers ", n);

for (c = 0; c n; c++) scanf("%d", &array);

for (c = 0; c (n - 1); c++) // finding minimum element (n-1) times position = c;

for (d = c + 1; d n; d++) if (array > array) position = d; if (position != c) t = array; array = array; array = t;

printf("Sorted các mục in ascending order: ");

for (c = 0; c n; c++) printf("%d ", array);

return 0;

Output of program:

*

Download Selection sort program.


C Hello worldPrint IntegerAddition of two numbersEven oddAdd, subtract, multiply và divideCheck vowelRoots of quadratic equationLeap year program in CSum of digitsFactorial program in CHCF and LCMDecimal to binary in CnCr & nPrAdd n numbersSwapping of two numbersReverse a numberPalindrome numberPrint PatternDiamondPrime numbersArmstrong numberArmstrong numbersFibonacci series in CFloyd"s triangle in CPascal triangle in CAddition using pointersMaximum element in arrayMinimum element in arrayLinear search in CBinary tìm kiếm in CReverse arrayInsert element in arrayDelete element from arrayMerge arraysBubble sort in CInsertion sort in CSelection sort in CAdd matricesSubtract matricesTranspose matrixMatrix multiplication in CPrint stringString lengthCompare stringsCopy stringConcatenate stringsReverse string Palindrome in CDelete vowelsC substringSubsequenceSort a stringRemove spacesChange caseSwap stringsCharacter"s frequencyAnagramsC read fileCopy filesMerge two filesList files in a directoryDelete fileRandom numbersAdd complex numbersPrint dateGet IP addressShutdown computer


Programming Simplified is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.