Answers for "example of selection sort in c"

C
0

Selection Sort in C

#include "stdio.h"
void main(){
    int n,arr[100],i,j;
    printf("Enter the size of array");
    scanf("%d",&n);
    printf("Enter the elements of the array");
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    int y;
    for(int j=0;j<n;j++)
    {
        for(int i=j+1;i<n;i++)
        {
            if(arr[i]<arr[j])
            {
                y=arr[i];
                arr[i]=arr[j];
                arr[j]=y;
            }
        }
    }
    printf("Correct Order:");
    for(i=0;i<n;i++)
    {
        printf("%d,",arr[i]);
    }
}
Posted by: Guest on February-18-2022

Code answers related to "C"

Browse Popular Code Answers by Language