Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- double* product(double arr[], int len) {
- double* result = new double[len];
- result[0] = arr[0];
- for (int i = 1; i < len; i++) {
- result[i] = arr[i] * result[i - 1];
- }
- return result;
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- int N{};
- double total_product{ 1 };
- string words_array[10]{ "перший", "другий", "третій", "четвертий", "п'ятий", "шостий", "сьомий", "восьмий", "дев'ятий", "десятий" };
- while (true) {
- cout << "Введіть бажану кількість елементів у масиві (від 2 до 10): ";
- cin >> N;
- if (cin.fail() || N < 2 || N > 10) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- double* array = new double[N];
- for (int i = 0; i < N; i++) {
- while (true) {
- cout << "Введіть " << words_array[i] << " елемент масиву: ";
- cin >> array[i];
- if (cin.fail()) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- }
- double* result = product(array, N);
- cout << "Новий масив: ";
- for (int i = 0; i < N; i++) {
- cout << result[i] << " ";
- total_product *= result[i];
- }
- cout << endl << "Добуток чисел в новому масиві: " << total_product;
- delete[] array;
- delete[] result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement