C program for selection sort

Posted Date:     Total Responses: 0    Posted By: Sunil Reddy   Member Level: Gold   Points/Cash: 2   

#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: “);
printf(“\nEnter the values one by one: “);
for (i = 0; i < maxsize; i++)
printf (“\nEnter element %i :”,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;

Project Feedbacks

No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: C program that uses a stack to check for matching left and right parentheses.
Previous Project: C program to count the number of words, lines and characters in a text

Return to Project Index

Post New Project

Related Projects

Top Contributors
TodayLast 7 Daysmore...

Awards & Gifts
ISC Technologies, Kochi - India. © All Rights Reserved.