Created
April 5, 2025 09:41
-
-
Save DO162/57f6910f633e2744918f3096d1faeae8 to your computer and use it in GitHub Desktop.
DZ_5_(20.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> | |
| using namespace std; | |
| int main() | |
| { | |
| setlocale(0, ""); | |
| //----------------------------------Задание 1---------------------------------- | |
| cout << "#1\n"; | |
| int sum = 0; | |
| for (int i = 0; i <= 10; i++) { | |
| sum += i; | |
| } | |
| cout << "Сума чисел в дiапазонi вiд 1 до 10: " << sum << "\n\n"; | |
| //----------------------------------Задание 2---------------------------------- | |
| cout << "#2\n"; | |
| cout << "Цельсiй | Фаренгейт" << "\n"; | |
| cout << "-------------------" << "\n"; | |
| for (int celsius = 0 ; celsius <= 100; celsius += 10) { | |
| double fahrenheit = celsius * 9 / 5 + 32; | |
| cout << celsius << " | " << fahrenheit << "\n"; | |
| } | |
| //----------------------------------Задание 3---------------------------------- | |
| cout << "\n#3\n"; | |
| srand(time(0)); | |
| rand(); | |
| int positiveNumbers = 0, negativeNumbers = 0, zeroNumbers = 0, evenNumbers = 0, oddNumbers = 0; | |
| const int SIZE = 100; | |
| int numbers[SIZE]{}; | |
| for (int i = 0; i < SIZE; i++) { | |
| numbers[i] = rand() % 201 - 100; | |
| cout << numbers[i] << ", "; | |
| if (numbers[i] > 0) positiveNumbers++; | |
| else if (numbers[i] < 0) negativeNumbers++; | |
| else zeroNumbers++; | |
| if (numbers[i] % 2 == 0) evenNumbers++; | |
| else oddNumbers++; | |
| } | |
| double positiveP = (positiveNumbers * 100) / SIZE; | |
| double negativeP = (negativeNumbers * 100) / SIZE; | |
| double zeroP = (zeroNumbers * 100) / SIZE; | |
| double evenP = (evenNumbers * 100) / SIZE; | |
| double oddP = (oddNumbers * 100) / SIZE; | |
| cout << "\n\nВiдсоток позитивних чисел: " << positiveP << "%\n"; | |
| cout << "Вiдсоток негативних чисел: " << negativeP << "%\n"; | |
| cout << "Вiдсоток нулiв: " << zeroP << "%\n"; | |
| cout << "Вiдсоток парних чисел: " << evenP << "%\n"; | |
| cout << "Вiдсоток непарних чисел: " << oddP << "%\n\n"; | |
| //----------------------------------Задание 4---------------------------------- | |
| cout << "#4\n"; | |
| int n, fact = 1; | |
| cout << "Введiть число: "; | |
| cin >> n; | |
| if (n < 0) { | |
| cout << "Не можна знайти факторiал вiд'ємного числа." << "\n"; | |
| } | |
| for (int i = 1; i <= n; i++) { | |
| fact *= i; | |
| } | |
| cout << "Факторiал: " << n << " = " << fact << ".\n\n"; | |
| //----------------------------------Задание 5---------------------------------- | |
| cout << "#5\n"; | |
| int num, suma = 0, count = 0; | |
| cout << "Введiть число: "; | |
| cin >> num; | |
| while (num != 0) { | |
| suma += num % 10; | |
| count++; | |
| num /= 10; | |
| } | |
| cout << "Кiлькiсть цифр: " << count << "\n"; | |
| cout << "Сума цифр: " << suma << "\n\n"; | |
| //----------------------------------Задание 6---------------------------------- | |
| cout << "#6\n"; | |
| cout << "Введiть число: "; | |
| int numb; | |
| cin >> numb; | |
| cout << "Числа, на якi " << numb << " дiлится без остачi: "; | |
| for (int i = 1; i <= numb; i++) { | |
| if (numb % i == 0) { | |
| cout << i << " "; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment