30 Commits

Author SHA1 Message Date
04f3343f0e Загрузить файлы в «/» 2025-09-30 15:12:52 +03:00
7dfb6397a6 Удалить task1.cpp 2025-09-30 15:12:38 +03:00
a48d56af9c Удалить task2.cpp 2025-09-30 15:12:33 +03:00
70cc38a754 Удалить tak3.cpp 2025-09-30 15:12:29 +03:00
25e99a12b8 Удалить summa.cpp 2025-09-30 15:12:24 +03:00
2897bf3465 Удалить sum.cpp 2025-09-30 15:12:21 +03:00
bab8e10eaa Удалить sum_calculator.cpp 2025-09-30 15:12:17 +03:00
581c38c331 Удалить remove_digits.cpp 2025-09-30 15:12:13 +03:00
48bdb950ba Удалить rectangle.cpp 2025-09-30 15:12:10 +03:00
88dd65175d Удалить range_checker.cpp 2025-09-30 15:12:06 +03:00
7c613a6c9c Удалить profit_analysis.cpp 2025-09-30 15:12:03 +03:00
e3f16c26e0 Удалить profit_6_months.cpp 2025-09-30 15:12:00 +03:00
8c0b94e39f Удалить print.cpp 2025-09-30 15:11:57 +03:00
b1622b22f5 Удалить network1.sh 2025-09-30 15:11:53 +03:00
76a7ebca6a Удалить mult.cpp 2025-09-30 15:11:48 +03:00
fa9ce8bb84 Удалить mergedarray.cpp 2025-09-30 15:11:42 +03:00
de3c05365f Удалить maxElem.cpp 2025-09-30 15:11:39 +03:00
ffd9fef3e5 Удалить lucky_number.cpp 2025-09-30 15:11:34 +03:00
b9863c0a3d Удалить funny_test.cpp 2025-09-30 15:11:31 +03:00
4c4ca3ff7d Удалить find_max.cpp 2025-09-30 15:11:27 +03:00
0be7e0edf5 Удалить elements.cpp 2025-09-30 15:11:24 +03:00
590f0f7e4d Удалить elem2.cpp 2025-09-30 15:11:20 +03:00
741be19f13 Удалить elem1.cpp 2025-09-30 15:11:15 +03:00
1e0dde9f12 Удалить checer.cpp 2025-09-30 15:11:12 +03:00
cf6215df42 Удалить bSearch.cpp 2025-09-30 15:11:09 +03:00
6721725272 Удалить Arr1-Arr2.cpp 2025-09-30 15:11:04 +03:00
af0e943ada Удалить analysis.cpp 2025-09-30 15:11:00 +03:00
9925e72fda Удалить 123.cpp 2025-09-30 15:10:57 +03:00
11b094b95b Удалить tac3.cpp 2025-09-30 15:10:52 +03:00
b3dbc2bdb9 Загрузить файлы в «/» 2025-09-30 15:09:25 +03:00
31 changed files with 168 additions and 2039 deletions

392
123.cpp
View File

@@ -1,392 +0,0 @@
//
//#include <iostream>
//#include <time.h>
//#define N 5
//const int m = 7;
//using namespace std;
//
///*
//type_or_void name_func(void_or_ type name1, type name2,..., type1 nameN=value){
////body
//return value;
//}
//
//*/
//
//double suma(int n = 7) {
// double x;
// double suma = 0;
// for (; n > 0; --n) {
// cout << "Input number: ";
// cin >> x;
// suma += x;
// }
// return suma;
//}
//
//
//double sumRec(int n, double arr[]) {//sum(n)=x+sum(n-1)
// if (n == 0) return 0;
// // double x;
// cout << "Input number: ";
// cin >> arr[n - 1];
// return arr[n - 1] + sumRec(n - 1, arr);
//}
//
//double sumRecNew(int n, double arr[], double s = 0, int i = 0) {
// if (i == n) return s;
// // double x;
// cout << "Input number: ";
// cin >> arr[i];
// return sumRecNew(n, arr, s + arr[i], i + 1);
//}
//
//
//
//
//
//double suma(double a[], int n) {
// double sum = 0;
// for (int i = n - 1; i >= 0; --i)
// sum += a[i];
// return sum;
//}
//
//
//void updateElement(double a[], int n) {
// for (int i = n / 2; i < n; ++i) {
// a[i] += a[0];
// }
//}
//
//void showArray(double a[], int n) {
// if (n < 2) return;
// for (int i = 0; i < n; ++i) {
// cout.width(4);
// cout << a[i];
// }
// cout << endl;
// return;
//}
//
//void showArray(int a[][m], int n) {
//
// for (int i = 0; i < n; ++i) {
// for (int j = 0; j < m; ++j) {
// cout.width(4);
// cout << a[i][j];
// }
// cout << endl;
// }
//
//}
//
//void updateArray(int a[][m], int index) {
// for (int i = 0; i < m; ++i) {
// a[index][i] *= -1;
// }
//}
//
//
//
//int main()
//{
// srand(time(NULL));
// const int n = 5;
// double a[5]{ 0 };
// /* cout << "Input n: ";
// cin >> n;*/
// double s = sumRec(n, a);
// cout << "\nArray1:\n";
// showArray(a, n);
// cout << "S= " << s << endl;
//
// s = sumRecNew(n, a);
// cout << "\nArray1:\n";
// showArray(a, n);
// cout << "S= " << s << endl;
//
//
//
//
// //const int n = 10;
// //double sum;// = suma(10);
// //cout << "sum(10) = \n" << sum
// // << "\nsum(7) = " << suma();
// //cout << "\n n(n>0)= ";
// // int n;
// //cin >> n;
// //if (n <= 0) {
// // cerr << "Error: " << n << " < 0 !!!!\n n= "<<-n<<endl;
// // n = -n;
// //}
// //sum = suma(n);
// //cout << "\nsum(" << n << ") = " << sum << endl;
//
// // double arr[n] = { -4,6,3,7,89,2,3,5,6 };
// // cout << "\n Array:\n";
// // showArray(arr, n);
// // sum = suma(arr,n);
// // cout << "\nArray sum(" << n << ") = " << sum << endl;
// // cout << "\n Array:\n";
// // showArray(arr, n/2);
// // sum = suma(arr, n/2);
// // cout << "\nArray sum(" << n/2 << ") = " << sum << endl;
//
// // cout << "\n Array:\n";
// // showArray(arr+2, n / 2);
// //sum = suma(arr+2, n / 2);
// // cout << "\nArray sum(" << n / 2 << ") = " << sum << endl;
//
// // cout << "\n Array:\n";
// // showArray(arr, n);
// // updateElement(arr, n);
// // cout << "\n New Array:\n";
// // showArray(arr, n);
//
// /* int arr[N][m]{ 0 };
// for (int i = 0; i < N; ++i)
// for (int j = 0; j < m; ++j)
// arr[i][j] = rand() % 100;
// cout << "\n Array:\n";
// showArray(arr, N);
// int index;
// cout << "0<= index < " << N - 1 << " ? ";
// cin >> index;
// if (index < 0 || index >= N) {
// index = N / 2;
// }
// updateArray(arr, index);
// cout << "\n new Array:\n";
// showArray(arr, N);*/
// system("pause");
//}
//
//
//
//
//
//#include <iostream>
//using namespace std;
//
//void print(int n) {
// if (n == 0) {
// return;
// }
// cout << "*";
// print(n - 1);
//}
//
//int main() {
// setlocale(0, "");
// int n;
// cout << "<22><><EFBFBD><EFBFBD>i<EFBFBD><69> <20>i<EFBFBD><69><EFBFBD>i<EFBFBD><69><EFBFBD> <20>i<EFBFBD><69><EFBFBD>: ";
// cin >> n;
//
// print(n);
// cout << endl;
//
// system("pause");
//}
//#include <iostream>
//using namespace std;
//
//int sum(int a, int b) {
// if (a > b) {
// return 0;
// }
// return a + sum(a + 1, b);
//}
//
//int main() {
// setlocale(0, "");
// int a;
// int b;
// cout << "<22><><EFBFBD><EFBFBD>i<EFBFBD><69> a: ";
// cin >> a;
// cout << "<22><><EFBFBD><EFBFBD>i<EFBFBD><69> b: ";
// cin >> b;
//
// cout << "<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20>i<EFBFBD> " << a << " <20><> " << b << " = " << sum(a, b) << endl;
//
// return 0;
//}
//#include <iostream>
//#include <time.h>
//#define N 5
//#define B 5
//using namespace std;
//
//int maxElem(int x, int y) {
// int max = (x > y) ? x : y;
// return max;
//}
//
//int maxElem(int x, int y, int z) {
// int max = (x > y) ? x : y;
// max = (max > z) ? max : z;
// return max;
//}
//
//int maxElem(int a[], int n) {
// int max = a[0];
// for (int i = 1; i < n; i++) {
// if (a[i] > max) {
// max = a[i];
// }
// }
// return max;
//}
//
//int maxElem(int a[][N], int n) {
// int max = a[0][0];
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < N; j++) {
// if (a[i][j] > max) {
// max = a[i][j];
// }
// }
// }
// return max;
//}
//
//int maxElem(int a[][N][B], int n) {
// int max = a[0][0][0];
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < N; j++) {
// for (int k = 0; k < B; k++) {
// if (a[i][j][k] > max) {
// max = a[i][j][k];
// }
// }
// }
// }
// return max;
//}
//
//int main() {
// srand(time(0));
// setlocale(0, "");
//
// int x = rand() % 100;
// int y = rand() % 100;
// int z = rand() % 100;
// cout << "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: x = " << x << ", y = " << y << ", z = " << z << endl;
// cout << "max(2): " << maxElem(x, y) << endl;
// cout << "max(3): " << maxElem(x, y, z) << endl << endl;
//
// int arr1[5];
// cout << "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ";
// for (int i = 0; i < 5; i++) {
// arr1[i] = rand() % 100;
// cout << arr1[i] << " ";
// }
// cout << "\nmax(1D): " << maxElem(arr1, 5) << endl << endl;
//
// int arr2[2][N];
// cout << "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n";
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < N; j++) {
// arr2[i][j] = rand() % 100;
// cout << arr2[i][j] << "\t";
// }
// cout << endl;
// }
// cout << "max(2D): " << maxElem(arr2, 2) << endl << endl;
//
// int arr3[2][N][B];
// cout << "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n";
// for (int i = 0; i < 2; i++) {
// cout << "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " << i << ":\n";
// for (int j = 0; j < N; j++) {
// for (int k = 0; k < B; k++) {
// arr3[i][j][k] = rand() % 100;
// cout << arr3[i][j][k] << "\t";
// }
// cout << endl;
// }
// cout << endl;
// }
// cout << "max(3D): " << maxElem(arr3, 2) << endl;
//
// return 0;
//}
#include <iostream>
#include <ctime>
using namespace std;
void bSort(int arr[], int size) {
for (int i = 0; i < size - 1; ++i) {
for (int j = 0; j < size - i - 1; ++j) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int bSearch(int arr[], int size, int target) {
int low = 0;
int high = size - 1;
while (low <= high) {
int m = low + (high - low) / 2;
if (arr[m] == target) {
return m;
}
if (arr[m] < target) {
low = m + 1;
}
else {
high = m - 1;
}
}
return -1;
}
int main() {
srand(time(0));
setlocale(0, "");
const int size = 10;
int arr[size];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: ";
for (int i = 0; i < size; ++i) {
arr[i] = rand() % 300 + 1;
cout << arr[i] << " ";
}
cout << endl;
bSort(arr, size);
cout << "<EFBFBD>i<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: ";
for (int i = 0; i < size; ++i) {
cout << arr[i] << " ";
}
cout << endl;
int t;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>i<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ";
cin >> t;
int index = bSearch(arr, size, t);
if (index != -1) {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> i<><69><EFBFBD><EFBFBD><EFBFBD>i (<28> <20>i<EFBFBD><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>i): " << index << endl;
}
else {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>." << endl;
}
return 0;
}

View File

@@ -1,31 +0,0 @@
#include <iostream>
using namespace std;
void show(int* a, int n) {
for (int i = 0; i < n; ++i, ++a) {
cout << *a << " ";
}
cout << "\n";
}
int main()
{
const int size = 7;
int arr1[size]{ 12, -5, 6, 7, 45, -6, 78 };
int arr2[size];
int* p1 = arr1;
int* p2 = arr2 + size - 1;
for (int i = 0; i < size; ++i, ++p1, --p2) {
*p2 = *p1;
}
cout << "Arr1: ";
show(arr1, size);
cout << "Arr2: ";
show(arr2, size);
return 0;
}

View File

@@ -1,48 +0,0 @@
#include <iostream>
using namespace std;
int main() {
setlocale(0, "");
double profit[12];
const char* months[12] = {
"Сень", "Лютий", "Березень", "Квiтень",
"Травень", "Червень", "Липень", "Серпень",
"Вересень", "Жовтень", "Листопад", "Грудень"
};
cout << "Введiть прибуток фiрми за кожен мiсяць року:" << endl;
for (int i = 0; i < 12; i++) {
cout << months[i] << ": ";
cin >> profit[i];
}
int maxIndex = 0;
for (int i = 1; i < 12; i++) {
if (profit[i] > profit[maxIndex]) {
maxIndex = i;
}
}
int minIndex = 0;
for (int i = 1; i < 12; i++) {
if (profit[i] < profit[minIndex]) {
minIndex = i;
}
}
double Sum = 0;
for (int i = 0; i < 12; i++) {
Sum += profit[i];
}
cout << "\nРезультати аналiзу:" << endl;
cout << "Мiсяць з максимальним прибутком: " << months[maxIndex]
<< " (прибуток: " << profit[maxIndex] << ")" << endl;
cout << "Мiсяць з мiнiмальним прибутком: " << months[minIndex]
<< " (прибуток: " << profit[minIndex] << ")" << endl;
cout << "Загальна сума прибутку за рiк: " << Sum << endl;
return 0;
}

View File

@@ -1,74 +0,0 @@
#include <iostream>
#include <ctime>
using namespace std;
void bSort(int arr[], int size) {
for (int i = 0; i < size - 1; ++i) {
for (int j = 0; j < size - i - 1; ++j) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int bSearch(int arr[], int size, int target) {
int low = 0;
int high = size - 1;
while (low <= high) {
int m = low + (high - low) / 2;
if (arr[m] == target) {
return m;
}
else if (arr[m] < target) {
low = m + 1;
}
else {
high = m - 1;
}
}
return -1;
}
int main() {
srand(time(0));
setlocale(0, "");
const int size = 10;
int arr[size];
cout << "Початковий масив: ";
for (int i = 0; i < size; ++i) {
arr[i] = rand() % 300 + 1;
cout << arr[i] << " ";
}
cout << endl;
bSort(arr, size);
cout << "Всортований масив: ";
for (int i = 0; i < size; ++i) {
cout << arr[i] << " ";
}
cout << endl;
int t;
cout << "Введiть елемент для пошуку: ";
cin >> t;
int index = bSearch(arr, size, t);
if (index != -1) {
cout << "Елемент знайдено на iндексi (у вiдсортованому масивi): " << index << endl;
}
else {
cout << "Елемент не знайдено." << endl;
}
return 0;
}

View File

@@ -1,38 +0,0 @@
#include <iostream>
using namespace std;
int main() {
setlocale(0, "");
int a;
int b;
int x;
cout << "Введiть нижню межу дiапазону: ";
cin >> a;
cout << "Введiть верхню межу дiапазону: ";
cin >> b;
if (a > b) {
int temp = a;
a = b;
b = temp;
cout << "Границi помiняно мiсцями. Дiапазон: [" << a << ", " << b << "]" << endl;
}
do {
cout << "Введiть число для перевiрки: ";
cin >> x;
if (x < a || x > b) {
cout << "Число " << x << " не потрапляє в дiапазон ["
<< a << ", " << b << "]" << endl;
}
} while (x < a || x > b);
cout << "Вiдмiнно! Число " << x << " потрапляє в дiапазон ["
<< a << ", " << b << "]" << endl;
return 0;
}

View File

@@ -1,61 +0,0 @@
#include <iostream>
#define N 5
#define M 7
using namespace std;
int main() {
setlocale(0, "");
srand(time(0));
int arr[N][M]{ 0 };
int i, j;
for (i = 0; i < N; ++i) {
for (j = 0; j < M; ++j) {
arr[i][j] = rand() % 55 + 2;
}
}
cout << "Показати масив (рядки):\n";
for (i = 0; i < N; ++i)
for (j = 0; j < M; ++j) {
cout.width(4);
cout << arr[i][j];
}
cout << endl;
int totalSum = 0;
int minElement = arr[0][0];
int maxElement = arr[0][0];
int elementCount = N * M;
for (i = 0; i < N; ++i) {
for (j = 0; j < M; ++j) {
totalSum += arr[i][j];
}
}
for (i = 0; i < N; ++i)
for (j = 0; j < M; ++j) {
if (arr[i][j] < minElement) {
minElement = arr[i][j];
}
if (arr[i][j] > maxElement) {
maxElement = arr[i][j];
}
}
double average = 0.0;
if (elementCount > 0) {
average = static_cast<double>(totalSum) / elementCount;
}
cout << "\nСума всіх елементів: " << totalSum << endl;
cout << "Середнє арифметичне всіх елементів: " << average << endl;
cout << "Мінімальний елемент: " << minElement << endl;
cout << "Максимальний елемент: " << maxElement << endl;
return 0;
}

View File

@@ -1,61 +0,0 @@
#include <iostream>
#define N 3
#define M 4
using namespace std;
int main() {
setlocale(0, "");
srand(time(0));
int arr[N][M]{ 0 };
int i;
int j;
int sum_r[N]{ 0 };
int sum_c[M]{ 0 };
int sum_all = 0;
for (i = 0; i < N; ++i) {
for (j = 0; j < M; ++j) {
arr[i][j] = rand() % 55 + 2;
}
}
cout << "Показати масив (рядки):\n";
for (i = 0; i < N; ++i) {
for (j = 0; j < M; ++j) {
sum_r[i] += arr[i][j];
cout.width(4);
cout << arr[i][j];
}
cout << " | " << sum_r[i] << endl;
}
for (i = 0; i < M + 2; ++i) {
cout << "----";
}
cout << endl;
for (j = 0; j < M; ++j) {
for (i = 0; i < N; ++i) {
sum_c[j] += arr[i][j];
}
}
for (i = 0; i < N; ++i) {
sum_all += sum_r[i];
}
for (j = 0; j < M; ++j) {
cout.width(4);
cout << sum_c[j];
}
cout << " | " << sum_all << endl;
system("pause");
return 0;
}

View File

@@ -1,64 +0,0 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
setlocale(0, "");
srand(time(0));
const int SiZE = 15;
int arr[SiZE];
for (int i = 0; i < SiZE; i++) {
arr[i] = rand() % 21 - 10;
}
cout << "Масив: ";
for (int i = 0; i < SiZE; i++) {
cout << arr[i] << " ";
}
cout << endl;
int count = 0;
int third = 0;
bool found = false;
for (int i = 0; i < SiZE; i++) {
if (arr[i] > 0) {
count++;
if (count == 3) {
third = arr[i];
found = true;
break;
}
}
}
int last = 0;
bool found2 = false;
for (int i = SiZE - 1; i >= 0; i--) {
if (arr[i] < 0) {
last = arr[i];
found2 = true;
break;
}
}
if (found) {
cout << "Третiй додатний елемент: " << third << endl;
}
else {
cout << "Третiй додатний елемент не знайдено" << endl;
}
if (found2) {
cout << "Останнiй вiд'ємний елемент: " << last << endl;
}
else {
cout << "Останнiй вiд'ємний елемент не знайдено" << endl;
}
return 0;
}

View File

@@ -1,47 +0,0 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
setlocale(0, "");
int n;
cout << "Введите размер массива n: ";
cin >> n;
if (n <= 0) {
cout << "n должно быть положительным" << endl;
return 1;
}
int *arr = new int[n];
srand(static_cast<unsigned int>(time(0)));
for (int i = 0; i < n; ++i) {
arr[i] = rand() % 61 - 30; // значения в диапазоне [-30; 30]
}
cout << "Array:\n";
for (int i = 0; i < n; ++i) {
cout.width(4);
cout << arr[i];
if ((i + 1) % 10 == 0) cout << endl;
}
if (n % 10 != 0) cout << endl;
int maxValue = arr[0];
int indexMax = 0;
for (int i = 1; i < n; ++i) {
if (arr[i] > maxValue) {
maxValue = arr[i];
indexMax = i;
}
}
cout << "max: " << maxValue << " index: " << indexMax << endl;
delete[] arr;
return 0;
}

View File

@@ -1,150 +0,0 @@
#include <iostream>
using namespace std;
int main() {
setlocale(0, "");
int correct = 0;
int answer;
cout << "=== ЖАРТiВЛИВИЙ ТЕСТ: ПЕРЕВiР СВОЇ МОЖЛИВОСТi ===" << endl;
cout << "Вiдповiдай на 7 питань. Удачi!" << endl << endl;
// Question 1
cout << "1) Професор лiг спати о 8 годинi, а встав о 9 годинi. Скiльки годин проспав професор?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 1:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 1 година." << endl;
break;
}
cout << endl;
// Question 2
cout << "2) На двох руках десять пальцiв. Скiльки пальцiв на 10 руках?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 50:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 50 пальцiв." << endl;
break;
}
cout << endl;
// Question 3
cout << "3) Скiльки цифр у дюжинi?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 2:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 2 цифри (1 i 2)." << endl;
break;
}
cout << endl;
// Question 4
cout << "4) Скiльки потрiбно зробити розпилiв, щоб розпиляти колоду на 12 частин?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 11:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 11 розпилiв." << endl;
break;
}
cout << endl;
// Question 5
cout << "5) Лiкар зробив три уколи в iнтервалi 30 хвилин. Скiльки часу вiн витратив?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 30:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 30 хвилин." << endl;
break;
}
cout << endl;
// Question 6
cout << "6) Скiльки цифр 9 в iнтервалi 1-100?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 1:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 1 (тiльки число 9)." << endl;
break;
}
cout << endl;
// Question 7
cout << "7) Пастух мав 30 овець. Усi, кроднiєї, розбiглися. Скiльки овець лишилося?" << endl;
cout << "Твоя вiдповiдь: ";
cin >> answer;
switch (answer) {
case 1:
cout << "Правильно!" << endl;
correct++;
break;
default:
cout << "Неправильно! Правильна вiдповiдь: 1 вiвця." << endl;
break;
}
cout << endl;
// Results
cout << "=== РЕЗУЛЬТАТИ ===" << endl;
cout << "Правильних вiдповiдей: " << correct << " з 7" << endl;
switch (correct) {
case 7:
cout << "ГЕНIЙ!" << endl;
break;
case 6:
cout << "ЕРУДИТ!" << endl;
break;
case 5:
cout << "НОРМАЛЬНИЙ!" << endl;
break;
case 4:
cout << "ЗДIБНОСТI СЕРЕДНI!" << endl;
break;
case 3:
cout << "ЗДIБНОСТI НИЖЧЕ СЕРЕДНЬОГО!" << endl;
break;
case 2:
case 1:
case 0:
cout << "ВАМ ТРЕБА ВIДПОЧИТИ!" << endl;
break;
default:
cout << "Помилка в пiдрахунку!" << endl;
break;
}
return 0;
}

View File

@@ -1,40 +0,0 @@
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a 6-digit number: ";
cin >> number;
// Check if the number is 6-digit (from 100000 to 999999)
if (number < 100000 || number > 999999) {
cout << "Error! Please enter exactly a 6-digit number (from 100000 to 999999)" << endl;
return 1;
}
// Extract digits separately
int digit1 = number / 100000; // first digit
int digit2 = (number / 10000) % 10; // second digit
int digit3 = (number / 1000) % 10; // third digit
int digit4 = (number / 100) % 10; // fourth digit
int digit5 = (number / 10) % 10; // fifth digit
int digit6 = number % 10; // sixth digit
// Calculate sums
int sum_first_three = digit1 + digit2 + digit3;
int sum_last_three = digit4 + digit5 + digit6;
// Check if lucky
if (sum_first_three == sum_last_three) {
cout << "Congratulations! Number " << number << " is lucky!" << endl;
cout << "Sum of first three digits: " << sum_first_three << endl;
cout << "Sum of last three digits: " << sum_last_three << endl;
} else {
cout << "Number " << number << " is not lucky." << endl;
cout << "Sum of first three digits: " << sum_first_three << endl;
cout << "Sum of last three digits: " << sum_last_three << endl;
}
return 0;
}

View File

@@ -1,100 +0,0 @@
#include <iostream>
#include <time.h>
#define N 5
#define B 5
using namespace std;
int maxElem(int x, int y) {
int max = (x > y) ? x : y;
return max;
}
int maxElem(int x, int y, int z) {
int max = (x > y) ? x : y;
max = (max > z) ? max : z;
return max;
}
int maxElem(int a[], int n) {
int max = a[0];
for (int i = 1; i < n; i++) {
if (a[i] > max) {
max = a[i];
}
}
return max;
}
int maxElem(int a[][N], int n) {
int max = a[0][0];
for (int i = 0; i < n; i++) {
for (int j = 0; j < N; j++) {
if (a[i][j] > max) {
max = a[i][j];
}
}
}
return max;
}
int maxElem(int a[][N][B], int n) {
int max = a[0][0][0];
for (int i = 0; i < n; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < B; k++) {
if (a[i][j][k] > max) {
max = a[i][j][k];
}
}
}
}
return max;
}
int main() {
srand(time(0));
setlocale(0, "");
int x = rand() % 100;
int y = rand() % 100;
int z = rand() % 100;
cout << "Случайные числа: x = " << x << ", y = " << y << ", z = " << z << endl;
cout << "max(2): " << maxElem(x, y) << endl;
cout << "max(3): " << maxElem(x, y, z) << endl << endl;
int arr1[5];
cout << "Одномерный массив: ";
for (int i = 0; i < 5; i++) {
arr1[i] = rand() % 100;
cout << arr1[i] << " ";
}
cout << "\nmax(1D): " << maxElem(arr1, 5) << endl << endl;
int arr2[2][N];
cout << "Двумерный массив:\n";
for (int i = 0; i < 2; i++) {
for (int j = 0; j < N; j++) {
arr2[i][j] = rand() % 100;
cout << arr2[i][j] << "\t";
}
cout << endl;
}
cout << "max(2D): " << maxElem(arr2, 2) << endl << endl;
int arr3[2][N][B];
cout << "Трехмерный массив:\n";
for (int i = 0; i < 2; i++) {
cout << "Плоскость " << i << ":\n";
for (int j = 0; j < N; j++) {
for (int k = 0; k < B; k++) {
arr3[i][j][k] = rand() % 100;
cout << arr3[i][j][k] << "\t";
}
cout << endl;
}
cout << endl;
}
cout << "max(3D): " << maxElem(arr3, 2) << endl;
return 0;
}

View File

@@ -1,63 +0,0 @@
#include <iostream>
using namespace std;
void show(int* a, int n) {
for (int i = 0; i < n; ++i, ++a) {
cout << *a << " ";
}
cout << "\n";
}
int main() {
srand(time(0));
int M, N;
cout << "Enter the size of array A: ";
if (!(cin >> M) || M <= 0) {
cerr << "Error: size A must be a positive number!\n";
return 1;
}
cout << "Enter the size of array B: ";
if (!(cin >> N) || N <= 0) {
cerr << "Error: size B must be a positive number!\n";
return 1;
}
int* A = new int[M];
int* B = new int[N];
for (int i = 0; i < M; i++) {
A[i] = rand() % 101 - 50;
}
for (int i = 0; i < N; i++) {
B[i] = rand() % 101 - 50;
}
int sizeC = M + N;
int* C = new int[sizeC];
int* pA = A;
int* pB = B;
int* pC = C;
for (int i = 0; i < M; i++, ++pA, ++pC) {
*pC = *pA;
}
for (int i = 0; i < N; i++, ++pB, ++pC) {
*pC = *pB;
}
cout << "Array A: ";
show(A, M);
cout << "Array B: ";
show(B, N);
cout << "C merged array: ";
show(C, sizeC);
delete[] A;
delete[] B;
delete[] C;
return 0;
}

View File

@@ -1,85 +0,0 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int l;
int q;
int c = 0;
srand(time(0));
cout << "=== ПЕРЕВiРКА ТАБЛИЦi МНОЖЕННЯ ===" << endl;
cout << "Оберiть рень складностi:" << endl;
cout << "1) Легкий (1-5, 5 питань)" << endl;
cout << "2) Середнiй (1-10, 7 питань)" << endl;
cout << "3) Важкий (1-15, 10 питань)" << endl;
cout << "Введiть номер рiвня (1-3): ";
cin >> l;
switch(l) {
case 1:
q = 5;
cout << "\n=== ЛЕГКИЙ РiВЕНЬ ===" << endl;
break;
case 2:
q = 7;
cout << "\n=== СЕРЕДНРiВЕНЬ ===" << endl;
break;
case 3:
q = 10;
cout << "\n=== ВАЖКИЙ РiВЕНЬ ===" << endl;
break;
default:
cout << "Невiрний вибiр!" << endl;
return 1;
}
for (int i = 1; i <= q; i++) {
int a;
int b;
int ans;
int user;
if (l == 1) {
a = rand() % 5 + 1;
b = rand() % 5 + 1;
} else if (l == 2) {
a = rand() % 10 + 1;
b = rand() % 10 + 1;
} else {
a = rand() % 15 + 1;
b = rand() % 15 + 1;
}
ans = a * b;
cout << "\nПитання " << i << "/" << q << ": " << a << " * " << b << " = ";
cin >> user;
if (user == ans) {
cout << "Правильно! +1 бал" << endl;
c++;
} else {
cout << "Неправильно! Правильна вiдповiдь: " << ans << endl;
}
}
cout << "\n=== РЕЗУЛЬТАТИ ===" << endl;
cout << "Правильних вiдповiдей: " << c << " з " << q << endl;
double p = (double)c / q * 100;
if (p >= 90) {
cout << "Оцiнка: ВМiННО! (5)" << endl;
} else if (p >= 80) {
cout << "Оцiнка: ДОБРЕ (4)" << endl;
} else if (p >= 70) {
cout << "Оцiнка: ЗАДОВЬНО (3)" << endl;
} else {
cout << "Оцiнка: НЕЗАДОВЬНО (2)" << endl;
}
return 0;
}

View File

@@ -1,344 +0,0 @@
#!/bin/bash
set -euo pipefail
readonly IPT=iptables
# ------------------------- Утилиты -------------------------
require_root() {
if [[ ${EUID:-$(id -u)} -ne 0 ]]; then
echo "[!] Пожалуйста, запустите скрипт от имени root (sudo)." >&2
exit 1
fi
}
ensure_dependencies() {
if ! command -v ${IPT} >/dev/null 2>&1; then
echo "[!] iptables не найден. Установите: apt update && apt install -y iptables" >&2
exit 1
fi
if ! command -v netfilter-persistent >/dev/null 2>&1; then
echo "[i] Устанавливаем iptables-persistent (без интерактивного режима)..."
DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1 || true
DEBIAN_FRONTEND=noninteractive apt-get install -y iptables-persistent netfilter-persistent >/dev/null 2>&1 || true
fi
}
validate_port() {
local port="$1"
[[ "$port" =~ ^[0-9]+$ ]] || return 1
(( port >= 1 && port <= 65535 ))
}
validate_protocol() {
local proto="$1"
case "$proto" in
tcp|udp|both) return 0 ;;
*) return 1 ;;
esac
}
validate_ip() {
local ip="$1"
# Принимаем IPv4 CIDR или одиночный IPv4
if [[ "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}(/([0-9]|[1-2][0-9]|3[0-2]))?$ ]]; then
IFS=/ read -r base _ <<<"$ip"
IFS=. read -r a b c d <<<"$base"
for o in "$a" "$b" "$c" "$d"; do
(( o >= 0 && o <= 255 )) || return 1
done
return 0
fi
return 1
}
# === Сохранение правил ===
save_rules() {
echo "[+] Сохраняем правила..."
# Используем iptables-persistent для сохранения правил
netfilter-persistent save >/dev/null 2>&1 || true
echo "[+] Правила сохранены."
}
# === Показать правила ===
show_rules() {
echo "========== IPTABLES RULES =========="
iptables -L -n -v --line-numbers
echo "========== DOCKER-USER RULES =========="
if iptables -S DOCKER-USER >/dev/null 2>&1; then
iptables -L DOCKER-USER -n -v --line-numbers
else
echo "(chain DOCKER-USER not present)"
fi
}
parse_port_rules() {
local chain="$1"
local action_filter="${2:-}" # ACCEPT or DROP
local src_filter="${3:-}" # -s IP
local rules
rules=$(iptables -S "$chain" 2>/dev/null)
if [[ -z "$rules" ]]; then
return
fi
echo "# Chain: $chain"
echo "# Protocol | Port | Action | Source IP"
echo "-------------------------------------------"
echo "$rules" | while read -r rule; do
local proto="-" port="-" action="-" src="-"
[[ "$rule" =~ -p\ (tcp|udp) ]] && proto="${BASH_REMATCH[1]}"
[[ "$rule" =~ --dport\ ([0-9]+) ]] && port="${BASH_REMATCH[1]}"
[[ "$rule" =~ -j\ (ACCEPT|DROP) ]] && action="${BASH_REMATCH[1]}"
[[ "$rule" =~ -s\ ([0-9\./]+) ]] && src="${BASH_REMATCH[1]}"
# Skip if no port rule or if action/src filter doesn't match
if [[ "$port" == "-" ]]; then continue; fi
if [[ -n "$action_filter" && "$action" != "$action_filter" ]]; then continue; fi
if [[ -n "$src_filter" && "$src" != "$src_filter" ]]; then continue; fi
printf "%-10s | %-7s | %-6s | %s\n" "$proto" "$port" "$action" "$src"
done
}
# === Показать открытые порты ===
show_open_ports() {
echo "\n========== ОТКРЫТЫЕ ПОРТЫ (ACCEPT) =========="
parse_port_rules INPUT ACCEPT
parse_port_rules DOCKER-USER ACCEPT
echo "============================================="
echo "[i] Если порт открыт, но не работает, убедитесь, что служба запущена и слушает этот порт (например, командой 'ss -tulpn | grep <PORT>')."
}
# === Показать закрытые порты (из DROP) ===
show_closed_ports() {
echo "\n========== ЗАКРЫТЫЕ ПОРТЫ (DROP) =========="
parse_port_rules INPUT DROP
parse_port_rules DOCKER-USER DROP
echo "==========================================="
}
show_all_ports() {
echo "\n========== ВСЕ ПОРТОВЫЕ ПРАВИЛА =========="
parse_port_rules INPUT
parse_port_rules DOCKER-USER
echo "=========================================="
}
# Helper for 'Press Enter to continue...'
press_enter() {
read -rp $'Нажмите Enter, чтобы продолжить...'
}
# === Блокировка IP ===
block_ip() {
read -p "Введите IP для блокировки: " ip
if ! validate_ip "$ip"; then echo "[!] Неверный IP-адрес."; press_enter; return; fi
iptables -A INPUT -s "$ip" -j DROP
iptables -A DOCKER-USER -s "$ip" -j DROP
echo "[+] IP $ip заблокирован."
save_rules
}
# === Разблокировка IP ===
unblock_ip() {
read -p "Введите IP для разблокировки: " ip
if ! validate_ip "$ip"; then echo "[!] Неверный IP-адрес."; press_enter; return; fi
iptables -D INPUT -s "$ip" -j DROP 2>/dev/null
iptables -D DOCKER-USER -s "$ip" -j DROP 2>/dev/null
echo "[+] IP $ip разблокирован."
save_rules
}
# === Ensure DOCKER-USER chain exists and hooked ===
ensure_docker_user_chain() {
iptables -S DOCKER-USER >/dev/null 2>&1 || iptables -N DOCKER-USER
iptables -C FORWARD -j DOCKER-USER >/dev/null 2>&1 || iptables -I FORWARD -j DOCKER-USER
}
# === Меню управления портами ===
ports_menu() {
while true; do
cat <<MENU
================ PORT MANAGER ================
1) Показать открытые порты
2) Показать закрытые порты
3) Показать все порты
4) Вернуться в главное меню
MENU
read -p "Выберите действие: " choice
case $choice in
1) show_open_ports; press_enter ;;
2) show_closed_ports; press_enter ;;
3) show_all_ports; press_enter ;;
4) break ;;
*) echo "Неверный выбор." ;;
esac
done
}
# === Главное меню ===
main_menu() {
while true; do
cat <<MENU
================ NETWORK MANAGER ================
1) Открыть порт
2) Закрыть порт
3) Добавить IP к порту
4) Убрать IP с порта
5) Показать правила
6) Порты (подменю)
7) Заблокировать IP
8) Разблокировать IP
9) Выход
MENU
read -p "Выберите действие: " action
case $action in
1) new_open_port; press_enter ;;
2) new_close_port; press_enter ;;
3) new_add_ip_to_port; press_enter ;;
4) new_remove_ip_from_port; press_enter ;;
5) show_rules; press_enter ;;
6) ports_menu ;;
7) block_ip; press_enter ;;
8) unblock_ip; press_enter ;;
9) echo "Выход"; exit 0 ;;
*) echo "Неверный выбор." ;;
esac
done
}
# --- Helper functions for managing iptables rules ---
add_port_rule() {
local chain="$1" proto="$2" port="$3" ip="$4" action="$5"
if [[ -z "$ip" ]]; then
${IPT} -A "$chain" -p "$proto" --dport "$port" -j "$action"
else
${IPT} -A "$chain" -p "$proto" --dport "$port" -s "$ip" -j "$action"
fi
}
delete_port_rule() {
local chain="$1" proto="$2" port="$3" ip="$4" action="$5"
if [[ -z "$ip" ]]; then
${IPT} -D "$chain" -p "$proto" --dport "$port" -j "$action" 2>/dev/null || true
else
${IPT} -D "$chain" -p "$proto" --dport "$port" -s "$ip" -j "$action" 2>/dev/null || true
fi
}
new_open_port() {
read -p "Введите номер порта: " port
if ! validate_port "$port"; then echo "[!] Неверный номер порта."; press_enter; return; fi
read -p "Протокол (tcp/udp/both): " proto
proto=$(echo "$proto" | tr '[:upper:]' '[:lower:]')
if ! validate_protocol "$proto"; then echo "[!] Неверный протокол."; press_enter; return; fi
read -p "Ограничить доступ по IP? (y/n): " limit
limit=$(echo "$limit" | tr '[:upper:]' '[:lower:]')
if [ "$proto" == "both" ]; then
protos=("tcp" "udp")
else
protos=("$proto")
fi
for p in "${protos[@]}"; do
# Удаляем ВСЕ существующие правила для этого порта из внешних цепочек
# Удаляем правила ACCEPT
while iptables -D INPUT -p "$p" --dport "$port" -j ACCEPT 2>/dev/null; do :; done
while iptables -D DOCKER-USER -p "$p" --dport "$port" -j ACCEPT 2>/dev/null; do :; done
# Удаляем правила DROP
while iptables -D INPUT -p "$p" --dport "$port" -j DROP 2>/dev/null; do :; done
while iptables -D DOCKER-USER -p "$p" --dport "$port" -j DROP 2>/dev/null; do :; done
if [ "$limit" == "y" ]; then
read -p "Введите IP-адреса (через пробел): " ips
for ip in $ips; do
if ! validate_ip "$ip"; then echo "[!] Пропускаем неверный IP: $ip"; continue; fi
iptables -I INPUT 1 -p "$p" --dport "$port" -s "$ip" -j ACCEPT
iptables -I DOCKER-USER 1 -p "$p" --dport "$port" -s "$ip" -j ACCEPT
done
else
iptables -I INPUT 1 -p "$p" --dport "$port" -j ACCEPT
iptables -I DOCKER-USER 1 -p "$p" --dport "$port" -j ACCEPT
fi
done
echo "[+] Порт $port открыт."
save_rules
}
new_close_port() {
read -p "Введите номер порта: " port
if ! validate_port "$port"; then echo "[!] Неверный номер порта."; press_enter; return; fi
read -p "Протокол (tcp/udp/both): " proto
proto=$(echo "$proto" | tr '[:upper:]' '[:lower:]')
if ! validate_protocol "$proto"; then echo "[!] Неверный протокол."; press_enter; return; fi
if [ "$proto" == "both" ]; then
protos=("tcp" "udp")
else
protos=("$proto")
fi
for p in "${protos[@]}"; do
# Удаляем ВСЕ существующие правила для этого порта из внешних цепочек
# Удаляем правила ACCEPT
while iptables -D INPUT -p "$p" --dport "$port" -j ACCEPT 2>/dev/null; do :; done
while iptables -D DOCKER-USER -p "$p" --dport "$port" -j ACCEPT 2>/dev/null; do :; done
# Удаляем правила DROP
while iptables -D INPUT -p "$p" --dport "$port" -j DROP 2>/dev/null; do :; done
while iptables -D DOCKER-USER -p "$p" --dport "$port" -j DROP 2>/dev/null; do :; done
# Добавляем новое правило DROP в НАЧАЛО внешних цепочек
iptables -I INPUT 1 -p "$p" --dport "$port" -j DROP
iptables -I DOCKER-USER 1 -p "$p" --dport "$port" -j DROP
done
echo "[+] Порт $port закрыт."
save_rules
}
new_add_ip_to_port() {
read -p "Введите номер порта: " port
if ! validate_port "$port"; then echo "[!] Неверный номер порта."; press_enter; return; fi
read -p "Протокол (tcp/udp): " proto
proto=$(echo "$proto" | tr '[:upper:]' '[:lower:]')
if ! validate_protocol "$proto"; then echo "[!] Неверный протокол."; press_enter; return; fi
read -p "Введите IP-адреса (через пробел): " ips
for ip in $ips; do
if ! validate_ip "$ip"; then echo "[!] Пропускаем неверный IP: $ip"; continue; fi
# Удаляем DROP для этого IP/порта из внешних цепочек
while iptables -D INPUT -p "$proto" --dport "$port" -s "$ip" -j DROP 2>/dev/null; do :; done
while iptables -D DOCKER-USER -p "$proto" --dport "$port" -s "$ip" -j DROP 2>/dev/null; do :; done
# Добавляем ACCEPT в начало внешних цепочек
iptables -I INPUT 1 -p "$proto" --dport "$port" -s "$ip" -j ACCEPT
iptables -I DOCKER-USER 1 -p "$proto" --dport "$port" -s "$ip" -j ACCEPT
echo "[+] Добавлен доступ для $ip на порт $port/$proto"
done
save_rules
}
new_remove_ip_from_port() {
read -p "Введите номер порта: " port
if ! validate_port "$port"; then echo "[!] Неверный номер порта."; press_enter; return; fi
read -p "Протокол (tcp/udp): " proto
proto=$(echo "$proto" | tr '[:upper:]' '[:lower:]')
if ! validate_protocol "$proto"; then echo "[!] Неверный протокол."; press_enter; return; fi
read -p "Введите IP-адрес: " ip
if ! validate_ip "$ip"; then echo "[!] Неверный IP-адрес."; press_enter; return; fi
# Удаляем ACCEPT для этого IP/порта из внешних цепочек
while iptables -D INPUT -p "$proto" --dport "$port" -s "$ip" -j ACCEPT 2>/dev/null; do :; done
while iptables -D DOCKER-USER -p "$proto" --dport "$port" -s "$ip" -j ACCEPT 2>/dev/null; do :; done
echo "[+] Убран доступ для $ip с порта $port/$proto"
save_rules
}
require_root
ensure_dependencies
ensure_docker_user_chain
main_menu

View File

@@ -1,22 +0,0 @@
#include <iostream>
using namespace std;
void print(int n) {
if (n == 0) {
return;
}
cout << "*";
print(n - 1);
}
int main() {
setlocale(0, "");
int n;
cout << "Введiть кiлькiсть зiрок: ";
cin >> n;
print(n);
cout << endl;
system("pause");
}

View File

@@ -1,27 +0,0 @@
#include <iostream>
#include <ctime>
using namespace std;
int main() {
setlocale(0, "");
const int n = 6;
srand(time(0));
double arr[n] = { 0 };
double sum = 0;
cout << "Input your profit values every month\n";
for (int i = 0; i < n; ++i) {
cout << "Month " << i + 1 << ": ";
cin >> arr[i];
}
for (int i = 0; i < n; ++i) {
sum += arr[i];
}
cout << "Your summary profit is " << sum << endl;
return 0;
}

View File

@@ -1,48 +0,0 @@
#include <iostream>
using namespace std;
int main() {
setlocale(0, "");
double profit[12];
const char* months[12] = {
"Сень", "Лютий", "Березень", "Квiтень",
"Травень", "Червень", "Липень", "Серпень",
"Вересень", "Жовтень", "Листопад", "Грудень"
};
cout << "Введiть прибуток фiрми за кожен мiсяць року:" << endl;
for (int i = 0; i < 12; i++) {
cout << months[i] << ": ";
cin >> profit[i];
}
int maxIndex = 0;
for (int i = 1; i < 12; i++) {
if (profit[i] > profit[maxIndex]) {
maxIndex = i;
}
}
int minIndex = 0;
for (int i = 1; i < 12; i++) {
if (profit[i] < profit[minIndex]) {
minIndex = i;
}
}
double totalSum = 0;
for (int i = 0; i < 12; i++) {
totalSum += profit[i];
}
cout << "\nРезультати аналiзу:" << endl;
cout << "Мiсяць з максимальним прибутком: " << months[maxIndex]
<< " (прибуток: " << profit[maxIndex] << ")" << endl;
cout << "Мiсяць з мiнiмальним прибутком: " << months[minIndex]
<< " (прибуток: " << profit[minIndex] << ")" << endl;
cout << "Загальна сума прибутку за рiк: " << totalSum << endl;
return 0;
}

View File

@@ -1,37 +0,0 @@
#include <iostream>
using namespace std;
int main() {
int a;
int b;
int x;
cout << "Введiть нижню межу дiапазону: ";
cin >> a;
cout << "Введiть верхню межу дiапазону: ";
cin >> b;
if (a > b) {
int temp = a;
a = b;
b = temp;
cout << "Границi помiняно мiсцями. Дiапазон: [" << a << ", " << b << "]" << endl;
}
do {
cout << "Введiть число для перевiрки: ";
cin >> x;
if (x < a || x > b) {
cout << "Число " << x << " не потрапляє в дiапазон ["
<< a << ", " << b << "]" << endl;
}
} while (x < a || x > b);
cout << "Вiдмiнно! Число " << x << " потрапляє в дiапазон ["
<< a << ", " << b << "]" << endl;
return 0;
}

View File

@@ -1,37 +0,0 @@
#include <iostream>
using namespace std;
void drawRectangle(int h, int w, char s = '*') {
if (h <= 0 || w <= 0) {
cout << "Помилка: висота та ширина повинні бути додатними числами!" << endl;
return;
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cout << s;
}
cout << endl;
}
}
int main() {
setlocale(0, "");
cout << "=== Приклади малювання прямокутників ===" << endl;
cout << "\nПрямокутник 5x10 зі зірочками (за замовчуванням):" << endl;
drawRectangle(5, 10);
cout << "\nПрямокутник 3x8 з символом '#' :" << endl;
drawRectangle(3, 8, '#');
cout << "\nПрямокутник 4x12 з символом '@' :" << endl;
drawRectangle(4, 12, '@');
cout << "\nПрямокутник 2x6 з символом '+' :" << endl;
drawRectangle(2, 6, '+');
return 0;
}

View File

@@ -1,29 +0,0 @@
#include <iostream>
using namespace std;
int main() {
int number;
int newNumber = 0;
int multiplier = 1;
cout << "Введiть цiле число: ";
cin >> number;
int originalNumber = number;
while (number > 0) {
int digit = number % 10;
if (digit != 3 && digit != 6) {
newNumber = newNumber + digit * multiplier;
multiplier *= 10;
}
number = number / 10;
}
cout << "Введене число: " << originalNumber << endl;
cout << "Нове число (без цифр 3 i 6): " << newNumber << endl;
return 0;
}

23
sum.cpp
View File

@@ -1,23 +0,0 @@
#include <iostream>
using namespace std;
int sum(int a, int b) {
if (a > b) {
return 0;
}
return a + sum(a + 1, b);
}
int main() {
setlocale(0, "");
int a;
int b;
cout << "Введiть a: ";
cin >> a;
cout << "Введiть b: ";
cin >> b;
cout << "Сума чисел вiд " << a << " до " << b << " = " << sum(a, b) << endl;
return 0;
}

View File

@@ -1,24 +0,0 @@
#include <iostream>
using namespace std;
int main() {
int number;
int sum = 0;
cout << "Введите числа (введите 0 для завершения):" << endl;
cout << "Введите число: ";
cin >> number;
while (number != 0) {
sum += number;
cout << "Текущая сумма: " << sum << endl;
cout << "Введите число: ";
cin >> number;
}
cout << "Итоговая сумма: " << sum << endl;
return 0;
}

View File

@@ -1,25 +0,0 @@
#include <iostream>
using namespace std;
int main()
{
const int size = 7;
int arr[size]{ 12, -5, 6, 7, 45, -6, 78 };
int* pI = arr;
int sum = 0;
cout << "Arr: ";
for (int i = 0; i < size; ++i) {
cout << arr[i] << " ";
}
cout << "\n";
for (int i = size; i > 0; --i, ++pI) {
sum += *pI;
}
cout << "Suma = " << sum << endl;
return 0;
}

View File

@@ -1,59 +0,0 @@
#include <iostream>
using namespace std;
void printNumbers(int n) {
if (n <= 0) {
cout << "Помилка: число повинно бути додатним!" << endl;
return;
}
int count = 0;
int totalNumbers = 0;
for (int i = 1; i <= n; ++i) {
cout << i << "\t";
count++;
totalNumbers++;
if (count == 7) {
cout << endl;
count = 0;
}
}
if (count > 0) {
cout << endl << "Останнiй рядок не повний. Збiльшуємо числа на 5:" << endl;
int startNumber = n - count + 1;
for (int i = startNumber; i <= n; ++i) {
cout << (i + 5) << "\t";
}
cout << endl;
}
}
int main() {
setlocale(0, "");
cout << "=== Завдання 3: Вивiд чисел по 7 в ряд ===" << endl;
cout << "\nПриклад 1: n = 15 (останнiй рядок не повний):" << endl;
printNumbers(15);
cout << "\nПриклад 2: n = 14 (останнiй рядок повний):" << endl;
printNumbers(14);
cout << "\nПриклад 3: n = 10 (останнiй рядок не повний):" << endl;
printNumbers(10);
cout << "\nПриклад 4: n = 21 (останнiй рядок повний):" << endl;
printNumbers(21);
int a;
cout << "\nВведiть кiлькiсть чисел: ";
cin >> a;
printNumbers(a);
return 0;
}

View File

@@ -1,28 +0,0 @@
#include <iostream>
using namespace std;
int main() {
setlocale(0, "");
int n;
int x = 0;
int m = 1;
cout << "Введiть цiле число: ";
cin >> n;
int old = n;
for (int i = n; i > 0; i = i / 10) {
int d = i % 10;
if (d != 3 && d != 6) {
x = x + d * m;
m = m * 10;
}
}
cout << "Введене число: " << old << endl;
cout << "Нове число (без цифр 3 i 6): " << x << endl;
return 0;
}

20
task1.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter a four-digit number: ";
cin >> n;
if (n < 1000 || n > 9999) {
cout << "Error! This is not a four-digit number." << endl;
} else {
int a = n / 1000;
int b = (n / 100) % 10;
int c = (n / 10) % 10;
int d = n % 10;
int r = c * 1000 + d * 100 + a * 10 + b;
cout << "Result: " << r << endl;
}
return 0;
}

121
task2.cpp
View File

@@ -1,82 +1,39 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int level;
int questions;
int correct = 0;
srand(time(0));
cout << "=== ПЕРЕВIРКА ТАБЛИЦI МНОЖЕННЯ ===" << endl;
cout << "Оберiть рень складностi:" << endl;
cout << "1) Легкий (1-5, 5 питань)" << endl;
cout << "2) Середнiй (1-10, 7 питань)" << endl;
cout << "3) Важкий (1-15, 10 питань)" << endl;
cout << "Введiть номер рiвня (1-3): ";
cin >> level;
switch(level) {
case 1:
questions = 5;
cout << "\n=== ЛЕГКИЙ РIВЕНЬ ===" << endl;
break;
case 2:
questions = 7;
cout << "\n=== СЕРЕДНРIВЕНЬ ===" << endl;
break;
case 3:
questions = 10;
cout << "\n=== ВАЖКИЙ РIВЕНЬ ===" << endl;
break;
default:
cout << "Невiрний вибiр!" << endl;
return 1;
}
for (int i = 1; i <= questions; i++) {
int a, b, answer, userAnswer;
if (level == 1) {
a = rand() % 5 + 1;
b = rand() % 5 + 1;
} else if (level == 2) {
a = rand() % 10 + 1;
b = rand() % 10 + 1;
} else {
a = rand() % 15 + 1;
b = rand() % 15 + 1;
}
answer = a * b;
cout << "\nПитання " << i << "/" << questions << ": " << a << " * " << b << " = ";
cin >> userAnswer;
if (userAnswer == answer) {
cout << "Правильно! +1 бал" << endl;
correct++;
} else {
cout << "Неправильно! Правильна вiдповiдь: " << answer << endl;
}
}
cout << "\n=== РЕЗУЛЬТАТИ ===" << endl;
cout << "Правильних вiдповiдей: " << correct << " з " << questions << endl;
double percentage = (double)correct / questions * 100;
if (percentage >= 90) {
cout << "Оцiнка: ВМIННО! (5)" << endl;
} else if (percentage >= 80) {
cout << "Оцiнка: ДОБРЕ (4)" << endl;
} else if (percentage >= 70) {
cout << "Оцiнка: ЗАДОВЬНО (3)" << endl;
} else {
cout << "Оцiнка: НЕЗАДОВЬНО (2)" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
double ab;
double bc;
double weight;
cout << "Distance A-B: ";
cin >> ab;
cout << "Distance B-C: ";
cin >> bc;
cout << "Cargo weight: ";
cin >> weight;
double fuel;
if (weight <= 500) fuel = 1;
else if (weight <= 1000) fuel = 4;
else if (weight <= 1500) fuel = 7;
else if (weight <= 2000) fuel = 9;
else {
cout << "The airplane cannot lift such a load!" << endl;
return 0;
}
double nAB = ab * fuel;
double nBC = bc * fuel;
if (nAB > 300) {
cout << "It is impossible to reach point B by flight." << endl;
}
else if (nBC > 300) {
cout << "It is impossible to fly from B to C." << endl;
}
else {
double fill = max(0.0, nBC - (300 - nAB));
cout << "Minimum refuel at B: " << fill << " liters." << endl;
}
return 0;
}

55
task3.cpp Normal file
View File

@@ -0,0 +1,55 @@
#include <iostream>
#include <clocale>
using namespace std;
int main() {
int c;
cout << "Menu:" << endl;
cout << "1. Income and delays -> lines of code" << endl;
cout << "2. Lines of code and desired salary -> delay" << endl;
cout << "3. Lines of code and delays -> salary" << endl;
cin >> c;
int l;
int t;
int s;
switch (c) {
case 1:
cout << "Enter the desired income ($): ";
cin >> s;
cout << "Enter the number of tardies: ";
cin >> t;
s += (t / 3) * 20;
l = (s / 50.0) * 100;
cout << "Vasyl needs to write " << l << " lines of code." << endl;
break;
case 2:
cout << "Enter the number of lines of code: ";
cin >> l;
cout << "Enter your desired salary ($): ";
cin >> s;
int b;
b = (l / 100) * 50;
cout << "Vasya can be late at most "
<< ((b - s) / 20) * 3 << " time(s)." << endl;
break;
case 3:
cout << "Enter the number of lines of code: ";
cin >> l;
cout << "Enter the number of tardies: ";
cin >> t;
s = (l / 100) * 50 - (t / 3) * 20;
if (s > 0)
cout << "Vasyl's salary: " << s << " $" << endl;
else
cout << "Vasya will not be paid anything." << endl;
break;
default:
cout << "Invalid choice." << endl;
}
return 0;
}

19
task4.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include <iostream>
#include <clocale>
using namespace std;
int main() {
int f;
cout << "Enter the finger number (1-5): ";
cin >> f;
switch (f) {
case 1: cout << "pollex" << endl; break;
case 2: cout << "index" << endl; break;
case 3: cout << "medius" << endl; break;
case 4: cout << "annularis" << endl; break;
case 5: cout << "digitus minimus" << endl; break;
default: cout << "Incorrect number!" << endl;
}
return 0;
}

35
task5.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include <iostream>
using namespace std;
int main() {
double a;
double b;
double c;
double x;
double y;
cout << "Enter the edges of the brick a, b, c: ";
cin >> a >> b >> c;
cout << "Enter the hole dimensions x, y: ";
cin >> x >> y;
double min1 = a, min2 = b;
if (c < min1) {
min2 = min1;
min1 = c;
}
else if (c < min2) {
min2 = c;
}
if ((min1 <= x && min2 <= y) || (min1 <= y && min2 <= x)) {
cout << "The brick will pass through the opening." << endl;
}
else {
cout << "The brick won't fit through the opening.." << endl;
}
return 0;
}