answersLogoWhite

0

#include<stdio.h> #include<conio.h> #define MAXSIZE 500 void selection(int elements[], int maxsize); int elements[MAXSIZE],maxsize; int main() { int i; printf("\nHow many elements you want to sort: "); scanf("%d",&maxsize); printf("\nEnter the values one by one: "); for (i = 0; i < maxsize; i++) { printf ("\nEnter element %i :",i); scanf("%d",&elements[i]); } printf("\nArray before sorting:\n"); for (i = 0; i < maxsize; i++) printf("[%i], ",elements[i]); printf ("\n"); selection(elements, maxsize); printf("\nArray after sorting:\n"); for (i = 0; i < maxsize; i++) printf("[%i], ", elements[i]); } void selection(int elements[], int array_size) { int i, j, k; int min, temp; for (i = 0; i < maxsize-1; i++) { min = i; for (j = i+1; j < maxsize; j++) { if (elements[j] < elements[min]) min = j; } temp = elements[i]; elements[i] = elements[min]; elements[min] = temp; } }

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How do you implement selection sort in c with graphics?

Selection sort has the following implementation: // sort an array if integers of length size in ascending order using selection sort algorithm: void selection_sort (int a[], unsigned size) { unsigned i, max; while (size &gt; 1) { max = 0; for (i=1; i!=size; ++i) if (a[i] &gt; a[max]) max = i; swap (a[max], a[--size]); } }


Write a program of binary heap in c or c language?

to implement operations on binary heap in c


Write a program in c language to implement framing methods like character stuffing?

A program in c language to implement framing methods like character stuffing can be grave sizeCRC-32 and the variable c50.


How do you run graphics program in C?

pro c language to implement linear search using pointers


Different types of sorting techniques in c language?

types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort


Simple c program for selection sort?

The Selection Sort definition is rather simple : find the largest number (element) in a list and move it to it's position in sorted form.You can perform selection sort like, smallest elements are in the beginning and largest element at the end.Now how this element arrange to it's exact position,We can do this by swapping elements at highest index and the process is continue till all the elements are sorted.


C program to implement arithmetic assignment operator?

y=2x2+3x+1


What is the C program for heap sort using recursion?

123


How do you program c plus plus to arrange 3 numbers in ascending order using swap?

void sort (int&amp; a, int&amp; b, int&amp; c) { if (a&gt;b) std::swap (a, b); if (b&gt;c) std::swap (b, c); else return; if (a&gt;b) std::swap (a, b); } Note that this is based upon a bubble sort algorithm. Although usually inefficient as a general sorting algorithm, given that we know there are only three elements means we can implement it reasonably efficiently without any additional space complexity. There will always be 2 or 3 comparisons but at most there will be 3 swaps. The only improvement we could really make is to implement a type of selection sort: void sort (int&amp; a, int&amp; b, int&amp; c) { if (a&gt;b &amp;&amp; a&gt;c) std::swap (a, c); else if (b&gt;c) std::swap (b, c); if (a&gt;b) std::swap (a, b); } Here we either make 3 or 4 comparisons but only 2 swaps at most. The assumption here is that a comparison is a quicker operation than a swap thus the selection sort method is more efficient. However, unless you were to sort millions of sets of three one after the other, you are unlikely to see any measurable difference in performance.


How do you implement a program to display the Indian flag with colors using c graphics?

ANSI/ISO C does not and never has done graphics.


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


Write a program in C language to implement the apriori algorithm?

JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.