• Предмет: Информатика
  • Автор: HunterDitX
  • Вопрос задан 5 месяцев назад

В одномерном массиве, состоящем из n целых элементов, вычислить:

А) произведение элементов массива, не больших заданного элемента С, значение С вводить с клавиатуры;

Б) количество элементов массива, расположенных после максимального элемента массива;

В) сумму элементов массива, расположенных до первого нулевого элемента.

На C++


flash77779: Виконав завдання

Ответы

Ответ дал: flash77779
0

#include <iostream>

#include <ctime>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

   srand(time(NULL));

   int n, C, max, sum, count;

   cout << "Enter the number of elements in the array: ";

   cin >> n;

   int *arr = new int[n];

   cout << "Enter the value of C: ";

   cin >> C;

   for (int i = 0; i < n; i++)

   {

       arr[i] = rand() % 100;

       cout << setw(4) << arr[i];

   }

   cout << endl;

   int product = 1;

   for (int i = 0; i < n; i++)

   {

       if (arr[i] <= C)

       {

           product *= arr[i];

       }

   }

   cout << "Product of array elements that are not greater than the given element C: " << product << endl;

   max = arr[0];

   for (int i = 0; i < n; i++)

   {

       if (arr[i] > max)

       {

           max = arr[i];

       }

   }

   cout << "Maximum array element: " << max << endl;

   count = 0;

   for (int i = 0; i < n; i++)

   {

       if (arr[i] == max)

       {

           count = n - i - 1;

       }

   }

   cout << "Number of array elements located after the maximum array element: " << count << endl;

   sum = 0;

   for (int i = 0; i < n; i++)

   {

       if (arr[i] == 0)

       {

           break;

       }

       sum += arr[i];

   }

   cout << "Sum of the array elements located before the first zero element: " << sum << endl;

   delete[] arr;

   return 0;

}

Приложения:
Вас заинтересует