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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 5 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> Enter \n");
|
|||
|
for (int i = 0; i < 5; i++) {
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> \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<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("1: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("2: x10 <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("3: <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("4: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 10\n");
|
|||
|
printf("5: 2X <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("6: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("7: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> -1\n");
|
|||
|
printf("8: <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 4\n");
|
|||
|
printf("9: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n"); //Var 1
|
|||
|
printf("11: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("12: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("13: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("14: <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0\n");
|
|||
|
printf("15: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|||
|
printf("\n");
|
|||
|
printf("0: <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>? <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = ");
|
|||
|
int index;
|
|||
|
scanf_s("%d", &index);
|
|||
|
|
|||
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = ");
|
|||
|
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);
|
|||
|
}
|