Created
April 7, 2025 15:24
-
-
Save DO162/aeda569655f0ee024e08e35845fa6b91 to your computer and use it in GitHub Desktop.
DZ_7_(27.03.25)
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 <algorithm> | |
using namespace std; | |
int main() | |
{ | |
setlocale(0, ""); | |
srand(time(0)); | |
rand(); | |
//----------------------------------Задание 1---------------------------------- | |
cout << "#1\n"; | |
int sumNumbers = 0; | |
const int SIZE = 10; | |
int numbers[SIZE]{}; | |
for (int a = 0; a < SIZE; a++) { | |
numbers[a] = rand() % 41 - 20; | |
cout << numbers[a] << ", "; | |
sumNumbers += numbers[a]; | |
} | |
double ArithmeticMeanNumbers = (double)sumNumbers / SIZE; | |
cout << "\nСумма чисел: " << sumNumbers << ".\n"; | |
cout << "Среднее арифметическое: " << ArithmeticMeanNumbers << ".\n\n"; | |
//----------------------------------Задание 2---------------------------------- | |
cout << "#2\n"; | |
cout << boolalpha; | |
cout << "Введiть цiле число: "; | |
int w = 0; | |
cin >> w; | |
const int size = 100; | |
int num[size]{}; | |
bool mass = false; | |
for (int b = 0; b < size; b++) { | |
num[b] = rand() % 101; | |
cout << num[b] << ", "; | |
} | |
for (int b = 0; b < size; b++) { | |
if (num[b] == w) { | |
cout << "\n\nЧисло '" << w << "' знайдено в масивi пiд iндексом - " << b << ".\n"; | |
mass = true; | |
cout << mass; | |
} | |
} | |
if (mass == false) { | |
cout << "\n\nЧисло '" << w << "' не знайдено в масивi.\n"; | |
cout << mass; | |
} | |
//----------------------------------Задание 3---------------------------------- | |
cout << "\n\n#3\n"; | |
const int s = 20; | |
int n[s]{}; | |
for (int c = 0; c < s; c++) { | |
n[c] = rand() % 21; | |
cout << n[c] << ", "; | |
} | |
cout << "\n\nМiнiмальний елемент масиву: " << *min_element(n, n + s) << '\n'; | |
cout << "Максимальний елемент масиву: " << *max_element(n, n + s) << '\n'; | |
//----------------------------------Задание 4---------------------------------- | |
cout << "\n#4\n"; | |
double oneDigit = 0, twoDigit = 0, threeDigit = 0; | |
const int sz = 200; | |
int nums[sz]; | |
for (int d = 0; d < sz; d++) { | |
nums[d] = rand() % 201; | |
cout << nums[d] << ", "; | |
} | |
for (int d = 0; d < sz; d++) { | |
if (nums[d] < 10) { | |
oneDigit++; | |
} | |
else if (nums[d] < 100) { | |
twoDigit++; | |
} | |
else { | |
threeDigit++; | |
} | |
} | |
cout << "\n\n" << oneDigit << " однозначних, " << twoDigit << " двозначних, " << threeDigit << " тризначних.\n"; | |
double onePercent = oneDigit / sz * 100; | |
double twoPercent = twoDigit / sz * 100; | |
double threePercent = threeDigit / sz * 100; | |
cout << "\n\nОднозначнi числа: " << onePercent << "%.\n"; | |
cout << "Двозначнi числа: " << twoPercent << "%.\n"; | |
cout << "Тризначнi числа: " << threePercent << "%.\n\n"; | |
//----------------------------------Задание 5---------------------------------- | |
cout << "#5\n"; | |
const int razm = 10, razmer = 10, raz = 5; | |
int chis[razm]{}; | |
int chislo[razmer]{}; | |
int chisl[raz]{}; | |
int m = 0; | |
for (int e = 0; e < razm; e++) { | |
chis[e] = rand() % 11; | |
cout << chis[e] << ", "; | |
} | |
cout << "\n\n"; | |
for (int q = 0; q < razmer; q++) { | |
chislo[q] = rand() % 11; | |
cout << chislo[q] << ", "; | |
} | |
for (int e = 0; e < razm; e++) { | |
for (int q = 0; q < razmer; q++) { | |
if (chis[e] == chislo[q]) { | |
chisl[m] = chis[e]; | |
} | |
} | |
} | |
cout << "\n\nСпільні елементи без повторень: "; | |
for (int p = 0; p < raz; p++) { | |
cout << chisl[p] << " "; | |
} | |
//----------------------------------Задание 6---------------------------------- | |
cout << "\n\n#6\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment