Created
April 2, 2025 18:49
-
-
Save Denkotleta221/e2acdeb73f2001bb14230d690a3d294d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <windows.h> | |
#include <algorithm> | |
#include <iomanip> | |
#include <conio.h> | |
#include <ctime> | |
using namespace std; | |
int main() | |
{ | |
srand(time(0)); | |
setlocale(LC_ALL, "RU"); | |
SetConsoleCP(CP_UTF8); | |
//1) Task | |
/*const int SIZE = 5; | |
int ar[SIZE] = { 1, 2, 3, 4, 5 }; | |
for (int elem : ar) { | |
cout << elem << endl; | |
} | |
cout << endl; | |
reverse(ar, ar + SIZE); | |
for (int elem : ar) { | |
cout << elem << endl; | |
}*/ | |
//2) Task | |
/*const int SIZE = 20; | |
int ar[SIZE]{}; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 100; | |
if (i % 2 == 0) { | |
if (i == 0) { | |
continue; | |
} | |
cout << ar[i] << " : " << i << endl; | |
} | |
}*/ | |
//3) Task | |
/*const int SIZE = 10; | |
int ar[SIZE]{}; | |
int sum = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 41 - 20; | |
cout << ar[i] << endl; | |
sum += ar[i]; | |
} | |
int avg = sum / SIZE; | |
cout << "Summa: " << sum << endl; | |
cout << "Avg: " << avg << endl;*/ | |
//5) Task !!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
/*const int SIZE = 100; | |
int ar[SIZE]{}; | |
int num; | |
cout << "Enter eny number: "; | |
cin >> num; | |
int times = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 100; | |
if (ar[i] == num) { | |
times += 1; | |
} | |
} | |
cout << "Your number was: " << times;*/ | |
//6) Task | |
/*const int SIZE = 20; | |
int ar[SIZE]{}; | |
int sum = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 41 - 10; | |
if (ar[i] < 0) { | |
for (int j = i + 1; j < SIZE; j++) | |
{ | |
ar[j] = rand() % 41 - 10; | |
cout << ar[j] << endl; | |
sum += ar[j]; | |
} | |
break; | |
} | |
} | |
cout << "Summa: " << sum;*/ | |
//7) Task | |
/*const int SIZE = 20; | |
int ar[SIZE]{}; | |
int sum = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 41 - 30; | |
if (ar[i] > 0) { | |
ar[i] = 0; | |
break; | |
} | |
cout << ar[i] << endl; | |
} | |
for (int elem : ar) | |
{ | |
sum += elem; | |
} | |
cout << "Summa: " << sum;*/ | |
//8) Task | |
/*const int SIZE = 20; | |
int ar[SIZE]{}; | |
int min = 100; | |
int max = 0; | |
int min_test = 0; | |
int index_min = 0; | |
int index_max = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 100; | |
cout << ar[i] << endl; | |
if (max < ar[i]) { | |
max = ar[i]; | |
index_max = i; | |
} | |
else if (ar[i] < min) { | |
min = ar[i]; | |
index_min = i; | |
} | |
} | |
cout << "Max: " << max << " Index: " << index_max << endl; | |
cout << "Min: " << min << " Index: " << index_min << endl;*/ | |
//10) Task !!!!!!!!!!!!!!!!!!!! | |
/*const int SIZE = 200; | |
int ar[SIZE]{}; | |
int one = 0; | |
int two = 0; | |
int tree = 0; | |
for (int i = 0; i < SIZE; i++) | |
{ | |
ar[i] = rand() % 200; | |
if (ar[i] <= 9) { | |
one++; | |
} | |
else if (ar[i] <= 99) { | |
two++; | |
} | |
else if (ar[i] > 99) { | |
tree++; | |
} | |
} | |
float one_digit = one / 2; | |
float two_digit = two / 2; | |
float tree_digit = tree / 2; | |
cout << "One-digit numbers: " << one_digit << "%" << endl; | |
cout << "Two-digit numbers: " << two_digit << "%" << endl; | |
cout << "Tree-digit numbers: " << tree_digit << "%" << endl;*/ | |
//Дано двовимірний масив розмірністю M x N, заповнений випадковими числами з діапазону від 0 до 20. Визначити суму елементів масиву, середнє арифметичне, мінімальний і максимальний елемент. | |
/*const int COL = 15; | |
const int ROW = 10; | |
int ar[ROW][COL]{}; | |
int sum = 0; | |
int max = 0; | |
int min = 20; | |
for (int i = 0; i < ROW; i++) | |
{ | |
for (int j = 0; j < COL; j++) | |
{ | |
ar[i][j] = rand() % 21; | |
sum += ar[i][j]; | |
if (max < ar[i][j]) { | |
max = ar[i][j]; | |
} | |
else if (ar[i][j] < min) { | |
min = ar[i][j]; | |
} | |
} | |
} | |
int avg = sum / (COL * ROW); | |
cout << "Summa: " << sum << endl; | |
cout << "Avg: " << avg << endl; | |
cout << "Max: " << max << endl; | |
cout << "Min: " << min << endl; | |
*/ | |
//Дано двовимірний масив розмірністю M x N, заповнений випадковими числами з діапазону від - 10 до 10. Визначити кількість додатних, від’ємних і нульових елементів. | |
/*const int COL = 15; | |
const int ROW = 10; | |
int ar[ROW][COL]{};*/ | |
/*int pluss = 0; | |
int minus = 0; | |
int zero = 0; | |
for (int i = 0; i < ROW; i++) | |
{ | |
for (int j = 0; j < COL; j++) { | |
ar[i][j] = rand() % 21 - 10; | |
if (ar[i][j] > 0) { | |
pluss++; | |
} | |
else if (ar[i][j] < 0) { | |
minus++; | |
} | |
else zero++; | |
} | |
} | |
cout << "Numbers with minus: " << minus << endl; | |
cout << "Numbers with pluss: " << pluss << endl; | |
cout << "Numbers zero: " << zero << endl;*/ | |
//Дано двовимірний масив розмірністю M x N, заповнений випадковими числами з діапазону від 0 до 20. Визначити суму по кожному рядку і по кожному стовпцю масиву. | |
/*const int COL = 15; | |
const int ROW = 10; | |
int ar[ROW][COL]{}; | |
for (int i = 0; i < ROW; i++) | |
{ | |
int sum_j = 0; | |
for (int j = 0; j < COL; j++) { | |
ar[i][j] = rand() % 21; | |
sum_j += ar[i][j]; | |
cout << left << setw(4) << ar[i][j]; | |
if (j == COL - 1) { | |
cout << " = " << sum_j; | |
} | |
} | |
cout << endl; | |
} | |
cout << endl; | |
for (int i = 0; i < COL; i++) | |
{ | |
int sum_i = 0; | |
for (int j = 0; j < ROW; j++) { | |
sum_i += ar[j][i]; | |
} | |
cout << left << setw(4) << sum_i; | |
}*/ | |
//Заповнити масив M x N двоцифровими числами так, щоб перша цифра вказувала номер рядка, а друга – номер стовпця. | |
/*const int COL = 10; | |
const int ROW = 10; | |
int ar[ROW][COL]{}; | |
for (int i = 1; i < ROW; i++) | |
{ | |
int index_i = 10 * i + 1; | |
for (int j = 1; j < COL; j++) { | |
ar[i][j] = index_i++; | |
cout << left << setw(6) << ar[i][j]; | |
} | |
cout << endl; | |
}*/ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment