C LANGUAGE BOOK |
WAP TO SORT THE NUMBER USING SELECTION SORT ENTER BY THE USER.
#include<stdio.h>
#define SIZE 100
void Sel_Sort(int q, int a[]);
int main()
{
int i,q;
int a[SIZE];
/* how many number will be entered */
printf("\n\nHow Many Number Will Be Entered :");
scanf("%d", &q);
for(i = 0; i < q; i++)
{
printf("\ni = %d \t a = ", i + 1);
scanf("%d", &a[i]);
}
/* Sort the elment using SelectionSort */
printf("\nSort The Number Using SelectionSort\n");
Sel_Sort(q, a);
/* Displya the Sorted numbers */
printf("\nThe Sorted Number Are:");
for(i = 0;i < q;i++)
printf("\ni = %d \t a = %d", i + 1, a[i]);
}
void Sel_Sort(int q,int a[])
{
int position,j,i,k,temp;
for(j=0;j < q;j++)
{
temp=9999;
for(k = j;k < q; k++)
{
if(temp>a[k])
{
temp=a[k];
position=k;
}
}
a[position] = a[j];
a[j] = temp;
printf("\nIteration j = %d ", j + 1);
for(i = 0; i < q; i++)
printf("\ni = %d \t a = %d", i + 1,a[i]);
}
return;
}
C LANGUAGE BOOK |
No comments:
Post a Comment