Selection sorting
#include <stdio.h>
#include <string.h>
void main()
{
int n,temp=0,o=1;
printf("Enter the amount of numbers to be entered:\n");
scanf("%d",&n);
int a[n]; //arrau Creation
//Filling the array
for(int i=0;i<n;i++)
{
printf("Enter the %d number:",i+1);
scanf("%d",&a[i]);
}
//sorting
for(int k=0;k<n-1;k++)
{
for(int j=o;j<n;j++)
{
if(a[k]>a[j])
{
temp=a[j];
a[j]=a[k];
a[k]=temp;
}
else
continue;
}
o++;
}
//printing
printf("Sorted in accending form:");
for(int p=0;p<n;p++)
{
printf("%d\n",a[p]);
}
}
Comments
Post a Comment