269 lines
4.4 KiB
C++
269 lines
4.4 KiB
C++
#include <stdio.h>
|
|
#include <Windows.h>
|
|
|
|
#define N_E 10
|
|
int item;
|
|
int arr[5];
|
|
|
|
void InputKey() {
|
|
printf("Ââåäèòå 5 ÷èñåë ÷åðåç Enter \n");
|
|
for (int i = 0; i < 5; i++) {
|
|
printf("Ââåäèòå ñëåäóþùåå ÷èñëî \n");
|
|
scanf_s("%d", &arr[i]);
|
|
}
|
|
for (int i1 = 0; i1 < 5; i1++) {
|
|
printf("%d ", arr[i1]);
|
|
}
|
|
}
|
|
|
|
void x10() {
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
if (arr[i] % 2 == 0) {
|
|
continue;
|
|
}
|
|
else {
|
|
arr[i] *= 10;
|
|
}
|
|
}
|
|
for (int i1 = 0; i1 < 5; i1++) {
|
|
printf("%d ", arr[i1]);
|
|
}
|
|
}
|
|
|
|
int minNum() {
|
|
int minNum1 = arr[0];
|
|
int saveNum = 0;
|
|
for (int i1 = 0; i1 < 5; i1++) {
|
|
if (arr[i1] < minNum1) {
|
|
minNum1 = arr[i1];
|
|
|
|
}
|
|
|
|
}
|
|
return minNum1;
|
|
}
|
|
|
|
int count10() {
|
|
int cnt = 0;
|
|
for (int i1 = 0; i1 < 5; i1++) {
|
|
if (arr[i1] > 10) {
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
return cnt;
|
|
}
|
|
|
|
int x2ForLast() {
|
|
int cnt;
|
|
for (int i = 4; i >= 0; i--) {
|
|
if (arr[i] % 2 == 0) {
|
|
cnt = i;
|
|
break;
|
|
}
|
|
}
|
|
return cnt;
|
|
}
|
|
|
|
int findIndexMin() {
|
|
int maxNum = 100000000;
|
|
int index = 0;
|
|
for (int i = 0; i < 5; i++) {
|
|
if (arr[i] < maxNum) {
|
|
index = i;
|
|
maxNum = arr[i];
|
|
}
|
|
}
|
|
return index;
|
|
}
|
|
|
|
void seven() {
|
|
for (int i = 0; i < 5; i++) {
|
|
if (arr[i] % 2 == 0) {
|
|
arr[i] *= -1;
|
|
}
|
|
}
|
|
for (int i = 0; i < 5; i++) {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
}
|
|
void eight() {
|
|
for (int i = 0; i < 5; i++) {
|
|
if (arr[i] < 4) {
|
|
arr[i] = 4;
|
|
}
|
|
}
|
|
for (int i = 0; i < 5; i++) {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
}
|
|
|
|
void nine() {
|
|
for (int i = 0; i < 5; i++) {
|
|
if (arr[i] % 2 == 0) {
|
|
arr[i] = 0;
|
|
}
|
|
}
|
|
for (int i = 0; i < 5; i++) {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
}
|
|
|
|
void deleteElement(int ind) {
|
|
for (int i = 0; i < 5; i++) {
|
|
if (i != ind) {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void insertElement(int index, int value) {
|
|
for (int i = 0; i < 5; i++) {
|
|
if (index == i) {
|
|
printf("%d ", value);
|
|
printf("%d ", arr[i]);
|
|
}
|
|
else {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
}
|
|
}
|
|
int minNum1() {
|
|
int minNum1 = arr[0];
|
|
int saveNum = 0;
|
|
for (int i1 = 0; i1 < 5; i1++) {
|
|
if (arr[i1] < minNum1) {
|
|
minNum1 = arr[i1];
|
|
saveNum = i1;
|
|
|
|
}
|
|
|
|
}
|
|
return saveNum;
|
|
}
|
|
|
|
void LastTask() {
|
|
bool flag = false;
|
|
for (int i = 0; i < 5; i++) {
|
|
if (arr[i] % 2 == 0 and flag == false) {
|
|
flag = true;
|
|
continue;
|
|
flag = true;
|
|
}
|
|
else {
|
|
printf("%d ", arr[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
SetConsoleCP(1251);
|
|
SetConsoleOutputCP(1251);
|
|
do {
|
|
printf("\nÂâåäèòå êîìàíäó\n");
|
|
printf("1: Ââåñòè ñ êëàâèàòóðû ìàññèâ\n");
|
|
printf("2: x10 äëÿ âñåõ íå÷åòíûõ ýëåìåíòîâ\n");
|
|
printf("3: Íàéòè ìèíèìàëüíûé ýëåìåíò\n");
|
|
printf("4: Ñêîëüêî ýëåìåíòîâ áîëüøå 10\n");
|
|
printf("5: 2X Ïîñëåäíåå ÷åòíîå ÷èñëî\n");
|
|
printf("6: Ñêîëüêî ÷åòíûõ ëåâåå ìèíèìàëüíîãî\n");
|
|
printf("7: Âñå ÷åòíûå ýëåìåíòû ìàññèâà óìíîæèòü íà -1\n");
|
|
printf("8: Âñå ýëåìåíòû ìàññèâà èìåþùèå çíà÷åíèÿ ìåíüøå 4 çàìåíèòü íà 4\n");
|
|
printf("9: Îáíóëèòü ÷åòíûå\n"); //Var 1
|
|
printf("11: Óäàëèòü çàäàííûé èíäåêñîì ýëåìåíò\n");
|
|
printf("12: Âñòàâêà íîâîãî ýëåìåíòà\n");
|
|
printf("13: Óäàëèòü ìèíèìàëüíûé ýëåìåíò\n");
|
|
printf("14: Ïåðåä ìèíèìàëüíûì ýëåìåíòîì âñòàâèòü 0\n");
|
|
printf("15: Óäàëèòü ïåðâûé èç ÷åòíûõ ýëåìåíòîâ\n");
|
|
printf("\n");
|
|
printf("0: Âûéòè èç ïðîãðàììû\n");
|
|
|
|
scanf_s("%d", &item);
|
|
switch (item) {
|
|
case 1:
|
|
InputKey();
|
|
break;
|
|
case 2:
|
|
x10();
|
|
break;
|
|
case 3: {
|
|
int min = minNum();
|
|
printf("Minimun in %d\n", min);
|
|
}
|
|
break;
|
|
case 4: {
|
|
int cnt = count10();
|
|
printf("Total nums higher 10 is %d\n", cnt);
|
|
}
|
|
break;
|
|
case 5: {
|
|
int index = x2ForLast();
|
|
if (index >= 0) {
|
|
arr[index] *= 2;
|
|
printf("That num now is %d", arr[index]);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 6: {
|
|
int index1 = findIndexMin();
|
|
printf("Index of min num is %d\n", index1);
|
|
|
|
int cnt = 0;
|
|
for (int i = 0; i <= index1; i++) {
|
|
if (arr[i] % 2 == 0) {
|
|
cnt++;
|
|
}
|
|
}
|
|
printf("Ëåâåå ìèíèìàëüíîãî %d ÷åòíûõ ýëåìåíòîâ\n", cnt);
|
|
}
|
|
break;
|
|
case 7:
|
|
seven();
|
|
break;
|
|
case 8:
|
|
eight();
|
|
break;
|
|
case 9:
|
|
nine();
|
|
break;
|
|
case 11: {
|
|
printf("Index deleting element = ");
|
|
int index1;
|
|
scanf_s("%d", &index1);
|
|
deleteElement(index1);
|
|
break;
|
|
}
|
|
|
|
case 12:
|
|
{
|
|
printf("Ïåðåä êàêèì ýëåìåíòîì ñòàâèòü íîâûé? Èíäåêñ = ");
|
|
int index;
|
|
scanf_s("%d", &index);
|
|
|
|
printf("\nÇíà÷åíèå = ");
|
|
int value;
|
|
scanf_s("%d", &value);
|
|
|
|
insertElement(index, value);
|
|
break;
|
|
}
|
|
case 13: {
|
|
int min = minNum1();
|
|
deleteElement(min);
|
|
break;
|
|
}
|
|
case 14: {
|
|
int min = minNum1();
|
|
insertElement(min, 0);
|
|
break;
|
|
}
|
|
case 15:
|
|
LastTask();
|
|
break;
|
|
}
|
|
|
|
} while (item != 0);
|
|
} |