Compare commits

...

3 Commits

Author SHA1 Message Date
b0c6f76b47 Merge pull request 'Ветвь1' (#1) from Ветвь into main
Reviewed-on: #1
2024-11-21 09:41:59 +04:00
cd51516e1e Second 2024-11-21 09:39:54 +04:00
39b4fb8f82 First 2024-11-21 09:39:05 +04:00

176
Lab Normal file
View File

@ -0,0 +1,176 @@
#include <stdio.h>
#include <Windows.h>
#define NUM_ELEMENTS 100
int arr[NUM_ELEMENTS];
int n = 0;
void addLastElement(int a) {
arr[n++] = a;
}
void printElements() {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int findMin() {
int min = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
int findMin2() {
int min = arr[0];
int o;
for (int i = 1; i < n; i++) {
if (arr[i] < min) {
min = arr[i];
o = i;
}
}
return o;
}
int findMax() {
int max = 0;
int o;
for (int i = 1; i < n; i++) {
if (arr[i] > max && arr[i]%2==0) {
max = arr[i];
o = i;
}
}
return o;
}
void keyboardInput() {
printf("n = ");
scanf_s("%d", &n);
printf("input %d values: ", n);
for (int i = 0; i < n; i++) {
scanf_s("%d", &arr[i]);
}
}
void deleteElement(int a){
int k = n;
printf("%d", k);
for (; a < n-1; a++) {
arr[a] = arr[a + 1];
}
n = n - 1;
}
void insertElement(int a,int b){
addLastElement(arr[n-1]);
int k = n;
int l = b;
printf("%d", k);
for (; a < k; k--) {
arr[k-1] = arr[k-2];
}
arr[a] = l;
}
void minEl0() {
int m = findMin();
int r;
int k = n;
for (int i = 0; i < n; i++) {
if (arr[i] == m) {
r = i;
}
}
addLastElement(arr[n - 1]);
printf("%d", k);
while (k > 0) {
arr[k] = arr[k - 1];
k--;
}
arr[r] = 0;
}
void priz() {
int m = findMax();
addLastElement(arr[n - 1]);
int r;
int k = n;
for (; m+2 < k; k--) {
arr[k] = arr[k - 1];
k--;
}
arr[m + 1] = 0;
}
void main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int item;
do {
printf("\n");
printf("------------------------------\n");
printf("Ñîäåðæèìîå ìàññèâà:");
printElements();
printf("Âûáåðèòå íóæíóþ âàì îïåðàöèþ:\n");
printf("1: Ââåñòè ñ êëàâèàòóðû ìàññèâ\n");
printf("2: Óäàëèòü âûáðàííûé ýëåìåíò\n");
printf("3: Ââåñòè ýëåìåíò íà âûáðàííîå ìåñòî\n");
printf("4: Óäàëèòü ìèíèìàëüíûé ýëåìåíò\n");
printf("5: Ïåðåä ìèíèìàëüíûì ýëåìåíòîì âñòàâèòü 0\n");
printf("6: Ïîñëå ìàêñèìàëüíîãî ÷¸òíîãî ýëåìåíòà âñòàâèòü 0\n");
printf("\n");
printf("0: Âûéòè èç ïðîãðàììû \n");
printf("Âûáðàííàÿ îïåðàöèÿ >>>>>> ");
scanf_s("%d", &item);
switch (item) {
case 1:
keyboardInput();
break;
case 2:
printf("Ââåäèòå èíäåêñ óäîëÿåìîãî ýëåìåíòà ");
int a;
scanf_s("%d", &a);
deleteElement(a);
break;
case 3:
{
printf("Ïðåä êàêèì ýëåìåíòîì âñòàâèòü íîâûé? Èíäåêñ = ");
int a;
scanf_s("%d", &a);
printf("Êàêîå çíà÷åíèå âñòàâèòü = ");
int b;
scanf_s("%d", &b);
insertElement(a,b);
break;
break;
}
case 4:
{
deleteElement(findMin2());
break;
}
case 5:
{
minEl0();
break;
}
case 6:
{
priz();
break;
}
}
} while (item != 0);
}