1 /* Program to Sort the Element by Selection Sort Technique */
2 /*
3 * CREATED ON MAR 27, 2004 8:03:45 PM
4 */
5 #include<stdio.h>
6 #include<conio.h>
7 #include<math.h>
8 void main()
9 {
10 int a[100],i,j,n,l,p,m,k;
11 clrscr();
12 printf("\n\t\t\tSELECTION SORT WAY - 2");
13 printf("\n\t\t\t~~~~~~~~~~~~~~~~~~~~~~");
14 printf("\n\nEnter How Many Terms ? :\n");
15 scanf("%d",&n);
16 printf("\nEnter the Values :\n");
17 for(i=1;i<=n;i++)
18 {
19 scanf("%d",&a[i]);
20 }
21 for(p=1;p<=n-1;p++)
22 {
23 printf("\nSTEP : %d\n",p);
24 for(j=p+1;j<=n;j++)
25 {
26 if(a[p]>a[j])
27 {
28 k=a[p];
29 a[p]=a[j];
30 a[j]=k;
31 }
32 for(l=1;l<=n;l++)
33 printf("%d\t",a[l]);
34 printf("\n");
35 getch();
36 }
37 }
38 }
39
40 And the model output is :
41 OUTPUT : -
42 ~~~~~~~~~~
43 SELECTION SORT WAY - 2
44 ~~~~~~~~~~~~~~~~~~~~~~
45
46 Enter How Many Terms ? :10
47
48 Enter the Values :1 2 4 3 5 6 8 7 9 0
49
50 STEP : 1
51 1 2 4 3 5 6 8 7 9 0
52 1 2 4 3 5 6 8 7 9 0
53 1 2 4 3 5 6 8 7 9 0
54 1 2 4 3 5 6 8 7 9 0
55 1 2 4 3 5 6 8 7 9 0
56 1 2 4 3 5 6 8 7 9 0
57 1 2 4 3 5 6 8 7 9 0
58 1 2 4 3 5 6 8 7 9 0
59 0 2 4 3 5 6 8 7 9 1
60
61 STEP : 2
62 0 2 4 3 5 6 8 7 9 1
63 0 2 4 3 5 6 8 7 9 1
64 0 2 4 3 5 6 8 7 9 1
65 0 2 4 3 5 6 8 7 9 1
66 0 2 4 3 5 6 8 7 9 1
67 0 2 4 3 5 6 8 7 9 1
68 0 2 4 3 5 6 8 7 9 1
69 0 1 4 3 5 6 8 7 9 2
70
71 STEP : 3
72 0 1 3 4 5 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