From cd70fde8332f00a3ef760d39e533618eb465ae89 Mon Sep 17 00:00:00 2001 From: augeliua Date: Thu, 14 Nov 2024 12:17:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=BE=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ОАиП_Lab_13/ОАиП_Lab_13/Source.cpp | 406 +++++++++------------ 1 file changed, 178 insertions(+), 228 deletions(-) diff --git a/ОАиП_Lab_13/ОАиП_Lab_13/Source.cpp b/ОАиП_Lab_13/ОАиП_Lab_13/Source.cpp index 01b2acb..f0a7b71 100644 --- a/ОАиП_Lab_13/ОАиП_Lab_13/Source.cpp +++ b/ОАиП_Lab_13/ОАиП_Lab_13/Source.cpp @@ -1,241 +1,191 @@ #include #include +#include -#define NUM_ELEMENTS 10 - -int arr[NUM_ELEMENTS]; -int n = 0; - -void printElements() { - for (int i = 0; i < n; i++) { - printf("%d ", arr[i]); - } -} - -void keyboardInput() { - printf("n = "); - scanf_s("%d", &n); - - printf(" %d : ", n); - for (int i = 0; i < n; i++) { - scanf_s("%d", &arr[i]); - } -} - -void oddsX10() { - for (int i = 0; i < n; i++) { - if (arr[i] % 2 == 1) { - arr[i] = arr[i] * 10; - } - } -} - -int findMin() { - int min = arr[0]; - for (int i = 1; i < n; i++) { - if (arr[i] < min) { - min = arr[i]; - } - } - return min; -} - -int FindIndexMin() { - int min = arr[0]; - int index = 0; - for (int i = 1; i < n; i++) { - if (arr[i] < min) { - min = arr[i]; - index = i; - } - } - return index; -} - -int MoreThan10() { - int cnt = 0; - for (int i = 0; i < n; i++) { - - if (arr[i] > 10) { - cnt += 1; - } - } - return cnt; -} - -void TwiceLastEven() { - int index = 0; - for (int i = 0; i < n; i++) { - if (arr[i] % 2 == 0) { - index = i; - } - } - arr[index] = 2 * arr[index]; -} - -void HowManyLeft() { - int index = FindIndexMin(); - printf(" = %d \n", index); - - int cnt = 0; - for (int i = 0; i < index; i++) { - if (arr[i] % 2 == 0) { - cnt++; - } - } - printf(" %d \n", cnt); -} - -void MinusEven() { - for (int i = 0; i < n; i++) { - if (arr[i] % 2 == 0) { - arr[i] = -1 * arr[i]; - } - } -} - -void OnlyMore4() { - for (int i = 0; i < n; i++) { - if (arr[i] < 4) { - arr[i] = 4; - } - } -} - -void BetweenEven() { - for (int i = 1; i < (n - 1); i++) { - if ((arr[i - 1] % 2 == 0) && (arr[i + 1] % 2 == 0)) { - arr[i] = 1; - } - } -} +// 3_1 +//void main() +//{ +// int a, b, minx, maxx; +// +// SetConsoleCP(1251); +// SetConsoleOutputCP(1251); +// +// printf(" "); +// scanf_s("%d", &a); +// printf(" "); +// scanf_s("%d", &b); +// if (a > b) { +// minx = b; +// maxx = a; +// } +// else { +// minx = a; +// maxx = b; +// } +// printf(" %d \n", minx); +// printf(" %d \n", maxx); +//} -// 14 +// 3_2 +//void main() +//{ +// int b, c, max; +// +// SetConsoleCP(1251); +// SetConsoleOutputCP(1251); +// +// printf(" : "); +// scanf_s("%d%d%d", &b, &c, &max); +// if (b > max) { +// max = b; +// } +// if (c > max) { +// max = c; +// } +// printf("Max = %d \n", max); +//} -void DeleteElement(int index) { - for (int i = index; i < (n - 1); i++) { - arr[i] = arr[i + 1]; - } - n--; -} -void InsertElement(int index, int value) { - for (int i = n; i > index; i--) { - arr[i] = arr[i - 1]; - } - n++; - arr[index] = value; -} +// 3_4 +//void main() +//{ +// int a, b, c, d, max; +// +// SetConsoleCP(1251); +// SetConsoleOutputCP(1251); +// +// printf(" : "); +// scanf_s("%d%d%d%d%d", &a, &b, &c, &d, &max); +// if (a > max) { +// max = a; +// } +// if (b > max) { +// max = b; +// } +// if (c > max) { +// max = c; +// } +// if (d > max) { +// max = d; +// } +// printf("Max = %d \n", max); +//} + +// 3_5 +// +//void main() +//{ +// int a; +// +// SetConsoleCP(1251); +// SetConsoleOutputCP(1251); +// +// printf(" "); +// scanf_s("%d", &a); +// if (a < -60) { +// printf(""); +// } +// if (a >= -60 && a < -40) { +// printf(""); +// } +// if (a >= -40 && a < -30) { +// printf(""); +// } +// if (a >= -30) { +// printf(""); +// } +//} + +// 3_6 +//K-pop +//void main() +//{ +// int a; +// +// SetConsoleCP(1251); +// SetConsoleOutputCP(1251); +// +// printf(" k-pop "); +// scanf_s("%d", &a); +// if (a < 1500) { +// printf(""); +// } +// if (a >= 1500 && a < 3000) { +// printf(""); +// } +// if (a >= 3000 && a < 5000) { +// printf(""); +// } +// if (a >= 5000) { +// printf(" "); +// } +//} + +// 3_7 +// +//void main() +//{ +// int a; +// +// SetConsoleCP(1251); +// SetConsoleOutputCP(1251); +// +// printf(" "); +// scanf_s("%d", &a); +// if (a < 3) { +// printf(" ( )"); +// } +// if (a >= 3 && a < 6) { +// printf(""); +// } +// if (a >= 6 && a < 10) { +// printf(""); +// } +// if (a >= 10) { +// printf(" "); +// } +//} + + +//LABA 4_1 +//void main() { +// int i; +// int n; +// printf("n = "); +// scanf_s("%d", &n); +// +// i = 1; +// do { +// printf("%d ", i); +// i = i + 1; +// } while (i <= n); +//} + +//LABA 4_2 +//void main() { +// int i, res; +// res = 1; +// i = 0; +// do { +// printf("2^%d = %d \n", i, res); +// i = i + 1; +// res = pow(2,i); +// } while (i <= 5); +//} + +//LABA 4_4 void main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); - int item; + int n, i; + printf(" n: "); + scanf_s("%d", &n); + i = 2; do { - printf("\n"); - printf("------------------------------\n"); - printf(" : "); - printElements(); - printf("\n"); - printf(" :\n"); - printf("1: \n"); - printf("2: x10 \n"); - printf("3: \n"); - printf("4: 10 \n"); - printf("5: 2 \n"); - printf("6: \n"); - printf("7: -1 \n"); - printf("8: , 4, 4 \n"); - printf("9: , , 1 \n"); - printf("10: \n"); - printf("11: \n"); - printf("12: \n"); - printf("13: 0 \n"); - printf("\n"); - printf("0: \n"); - printf(" >>>>>> "); - - scanf_s("%d", &item); - - switch (item) { - case 1: - keyboardInput(); - break; - - case 2: - oddsX10(); - break; - - case 3: - { - int min = findMin(); - printf("min = %d\n", min); - break; - } - - case 4: - { - int cnt = MoreThan10(); - printf("%d 10 \n", cnt); - break; - } - - case 5: - TwiceLastEven(); - break; - - case 6: - HowManyLeft(); - break; - - case 7: - MinusEven(); - break; - - case 8: - OnlyMore4(); - break; - case 9: - BetweenEven(); - break; - - // 14 - case 10: - { - printf(" : "); - int index; - scanf_s("%d", &index); - DeleteElement(index); - break; - } - case 11: - { - printf(" ? : "); - int index; - scanf_s("%d", &index); - - printf(", = "); - int value; - scanf_s("%d", &value); - - InsertElement(index, value); - break; - } - case 12: - { - int min = FindIndexMin(); - printf("min = %d", arr[min]); - DeleteElement(min); - break; - } - case 13: - { - int min = FindIndexMin(); - InsertElement(min, 0); - break; - } - } - - } while (item != 0); + printf("%d \n", i); + i = i + 2; + n = n - 1; + } while (n != 0); } \ No newline at end of file