Home » C Programs » C Program to Implement Selection Sort

C Program to Implement Selection Sort

C Program to implement selection sort. This is a sorting program using the concept of selection sorting in c. The selection sort program is done by the value of the sorting element will be selected before the programs output, this process is known as selection sorting in c.

Count Keyword in Selection Sort

Using Functions, count the number of digits in a number in C. The user can enter any positive integer into this program to count the number of digits. Then, using Functions, it divides the given number into individual digits and counts those digits.

For Loop in C

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times. The loop allows us to perform an arbitrary number of steps in a single line. Looping statement to execute the c program to implement selection sort

Temporary Variable Definition in C

A temporary variable is a variable in computer programming that has a short lifetime and is used to hold data that will be discarded soon or before it can be stored in a more permanent memory location. It is usually declared as a local variable, or a variable with local scope, because it is short-lived. 

Decision Making Statement in C

Statements that make decisions are also known as selection statements. That is, depending on whether or not the condition block should be executed, which is determined by the condition. 

C Program to Implement Selection Sort

//c program to implement selection sort
#include<stdio.h>
int main()
{
int i, j, count, temp, num[10];
printf("How many nums");
scanf("%d",&count);
printf("Enter %d elements: ", count);
for(i=0;i<count;i++)
scanf("%d",&num[i]);
for(i=0;i<count;i++)
{
for(j=i+1;j<count;j++)
{
if(num[i]>num[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
printf("After sorting");
for(i=0;i<count;i++)
printf(" %d",num[i]);
return 0;
}

Output

How many nums

5

Enter 5 elements:

45 67 78 89 34

After sorting

34 45 67 78 89