-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex-casa.c
176 lines (143 loc) · 3.33 KB
/
ex-casa.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <limits.h>
#include <stdio.h>
void AddNumbers(int numbers[], int DIM, int *i, int *sentinella)
{
int z;
printf("Enter a series of numbers, stop by entering the value -1\n");
do
{
scanf("%d", &z);
if (z != -1)
{
numbers[*i] = z;
(*i)++;
(*sentinella)++;
}
} while (z != -1 && z < DIM);
}
void ShowNumbers(int numbers[], int *i)
{
for (int a = 0; a < *i; a++)
{
if (a == 0)
{
printf("numbers entered\n");
printf("%d,", numbers[a]);
}
else
printf("%d,", numbers[a]);
}
}
void EnterLastNumber(int numbers[], int *i)
{
printf("enter a number in the last position\n");
scanf("%d", &numbers[*i]);
(*i)++;
}
void Modify(int numbers[])
{
int pos;
printf("which position to change?\n");
scanf("%d", &pos);
if (pos >= 0)
{
printf("enter the new number\n");
scanf("%d", &numbers[pos]);
}
else
printf("unidentified number\n");
}
void delete (int numbers[], int *i)
{
int SrchN, cnt = 0;
printf("which number to delete?\n");
scanf("%d", &SrchN);
for (int w = 0; w < (*i); w++)
{
if (numbers[w] == SrchN)
{
cnt = 2;
printf("number deleted\n");
}
if (cnt == 2)
numbers[w] = numbers[w + 1];
}
(*i)--;
if (cnt == 0)
{(*i)++;
printf("number doesn't exists\n");}
}
void search(int numbers[], int *sentinella)
{
int SrchN, cnt = 0;
printf("which number to search?\n");
scanf("%d", &SrchN);
for (int b = 0; b < *sentinella; b++)
{
if (numbers[b] == SrchN)
{
cnt = b;
printf("number %d exist in posistion%d\n", SrchN, cnt);
}
}
if (cnt == 0)
printf("number doesn't exists\n");
}
void delNmbPos(int numbers[], int *i)
{
int Srch, cnt = 0;
printf("which posistion to delete?\n");
scanf("%d", &Srch);
for (int w = 0; w < (*i); w++)
{
if (w == Srch)
{
cnt = 2;
printf("number deleted\n");
}
if (cnt == 2)
numbers[w] = numbers[w + 1];
}
(*i)--;
}
int main(int argc, char *argv[])
{
int DIM = SHRT_MAX;
int i = 0, sentinella = 0;
int numbers[DIM];
AddNumbers(numbers, DIM, &i, &sentinella);
int p;
do
{
printf("\npress 1 to show numbers\n");
printf("press 2 to enter a number in the last position\n");
printf("press 3 to modify a number\n");
printf("press 4 to delete a number\n");
printf("press 5 to search a number\n");
printf("press 6 to delete a number with position\n");
printf("press 0 to exit\n");
scanf("%d", &p);
switch (p)
{
case 1:
ShowNumbers(numbers, &i);
break;
case 2:
EnterLastNumber(numbers, &i);
break;
case 3:
Modify(numbers);
break;
case 4:
delete (numbers, &i);
break;
case 5:
search(numbers, &sentinella);
break;
case 6:
delNmbPos(numbers, &i);
break;
}
} while (p > 0 && p <= 6);
return 0;
}