-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selection_Sort.c
64 lines (60 loc) · 1.25 KB
/
Selection_Sort.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
printf("Q1...........\n");
int q,w,c,temp,cho;
printf("enter the length of array: \n");
scanf("%d",&c);
int ar[c];
printf("Enter %d number : \n",c);
for(q =0 ; q<c ;q++)
{
scanf("%d",&ar[q]);
}
printf("ascending order press 0 , descending order press 1 \n");
scanf("%d",&cho);
if (cho == 0 )
{
for(q=0;q<5;q++)
{
for(w=q+1 ;w<5;w++)
{
if(ar[q]>ar[w])
{
temp=ar[q];
ar[q]=ar[w];
ar[w]=temp;
}
}
}
printf("Array elements: ");
for(q=0;q<5;q++)
{
printf("%d ",ar[q]);
}
}
else
{
for(q=0;q<5;q++)
{
for(w=q+1 ;w<5;w++)
{
if(ar[q]<=ar[w])
{
temp=ar[q];
ar[q]=ar[w];
ar[w]=temp;
}
}
}
printf("Array elements: ");
for(q=0;q<5;q++)
{
printf("%d ",ar[q]);
}
}
printf("\n");
return 0;
}