#include <stdio.h>
int main()
{
int a[100], n,
i, j, temp, swap;
printf("Enter number of elements \n");
scanf("%d", &n);
printf("Enter %d Numbers \n", n);
for (i = 0; i
< n; i++)
scanf("%d", &a[i]);
for(i = 0; i < n - 1; i++)
{
temp=i;
for(j = i + 1; j < n; j++)
{
if(a[temp] > a[j])
temp=j;
}
if(temp != i)
{
swap=a[i];
a[i]=a[temp];
a[temp=swap;
}
}
printf("Sorted Array:\n");
for(i = 0; i < n; i++)
printf("%dn", a[i]);
return 0;
}
Output-:
Please See All Array Blogs
ReplyDelete