-
Notifications
You must be signed in to change notification settings - Fork 0
/
INS.C
86 lines (79 loc) · 1.46 KB
/
INS.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// to arrange the numbers in ascending order and descending order :1(a)(b)
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int n[90],i=0,j=0,k=0,temp,h,it;
char an='Y',x;
while(toupper(an)=='Y')
{
clrscr();
gotoxy(5,5);
textcolor(LIGHTGRAY);
cprintf("enter the number :");
textcolor(CYAN);
cscanf("%d",&n[i]);
i++;
textcolor(LIGHTGRAY);
gotoxy(5,7);
cprintf("another number y/n...? ");
fflush(stdin);
an=getchar();
}
fflush(stdin);
textcolor(LIGHTGRAY);
gotoxy(5,8);
cprintf(" Arrange the numbers in ascending or descending order : A/D ...?");
scanf("%c",&x);
it=x;
x=toupper(x);
if(x=='A'|| it==10)
{
textcolor(WHITE);
if(it==10)
cprintf(" By default Ascending ");
textcolor(CYAN);
/* insertion sort method */
while(j<i)
{
for(k=0;k<i-1;k++)
if(n[k] > n[k+1])
{
temp=n[k];
n[k]=n[k+1];
n[k+1]=temp;
}
j++;
}
}
else
for(j=0;j<i;j++)
if(x=='D')
{
for(j=0;j<i;j++)
for(k=0;k<i-1;k++)
if(n[k] < n[k+1])
{
temp=n[k];
n[k]=n[k+1];
n[k+1]=temp;
}
}
else
{
printf("don'nt play games with me , re run the program");
exit();
}
gotoxy(5,10);
cprintf(" the numbers in the sorted order are :");
for(h=0;h<i;h++)
{
printf(" %d ",n[h]);
}
getch();
gotoxy(5,19);
cprintf(" press any key to exit... ");
while(!kbhit());
system("cls");
}