Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- template<typename T, size_t N>
- bool arraysEqual(const T(&a)[N], const T(&b)[N]) {
- for (size_t i = 0; i < N; i++) {
- if (a[i] != b[i]) {
- return false;
- }
- }
- return true;
- }
- int main() {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- const int N = 5;
- int choice{};
- while (true) {
- cout << "Оберіть тип масиву:" << endl;
- cout << "1 - Цілі числа" << endl;
- cout << "2 - Числа з плаваючою комою" << endl;
- cout << "Введіть 1 або 2: ";
- cin >> choice;
- if (cin.fail() || (choice != 1 && choice != 2)) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- }
- else {
- break;
- }
- }
- if (choice == 1) {
- int arr1[N]{};
- int arr2[N]{};
- cout << "Введіть 5 цілих чисел першого масиву: " << endl;
- for (int i = 0; i < N; i++) {
- cin >> arr1[i];
- }
- cout << "Введіть 5 цілих чисел другого масиву: " << endl;
- for (int i = 0; i < N; i++) {
- cin >> arr2[i];
- }
- if (arraysEqual(arr1, arr2)) {
- cout << "Масиви рівні" << endl;
- }
- else {
- cout << "Масиви не рівні" << endl;
- }
- }
- else if (choice == 2) {
- double arr1[N]{};
- double arr2[N]{};
- cout << "Введіть 5 чисел з плаваючою комою першого масиву:" << endl;
- for (int i = 0; i < N; i++) {
- cin >> arr1[i];
- }
- cout << "Введіть 5 чисел з плаваючою комою другого масиву:" << endl;
- for (int i = 0; i < N; i++) {
- cin >> arr2[i];
- }
- if (arraysEqual(arr1, arr2)) {
- cout << "Масиви рівні" << endl;
- }
- else {
- cout << "Масиви не рівні" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement