В С++ В одномерном массиве, состоящем из п вещественных элементов, вычислить: 1) количество отрицательных элементов массива; 2) сумму модулей элементов массива, расположенных после минимального по модулю элемента. Заменить все отрицательные элементы массива их квадратами и упорядочить элементы массива по возрастанию

22 Июн 2021 в 19:44
378 +1
0
Ответы
1
include include include

using namespace std;

int main()
int n
cout << "Enter the number of elements in the array: "
cin >> n;

double* arr = new double[n]
cout << "Enter the elements of the array: "
for(int i = 0; i < n; i++)
cin >> arr[i]

// 1) Counting the number of negative element
int count_negative = 0
for(int i = 0; i < n; i++)
if(arr[i] < 0)
count_negative++

cout << "Number of negative elements in the array: " << count_negative << endl
// 2) Finding the minimum element by absolute valu
double min_abs = abs(arr[0])
int min_index = 0
for(int i = 1; i < n; i++)
if(abs(arr[i]) < min_abs)
min_abs = abs(arr[i])
min_index = i

// Calculating the sum of absolute values of elements after the minimum elemen
double sum_abs = 0
for(int i = min_index + 1; i < n; i++)
sum_abs += abs(arr[i])

cout << "Sum of absolute values of elements after the minimum element: " << sum_abs << endl
// Replacing negative elements with their square
for(int i = 0; i < n; i++)
if(arr[i] < 0)
arr[i] = pow(arr[i], 2)

// Sorting the array in ascending orde
sort(arr, arr + n)
// Printing the modified arra
cout << "Modified array in ascending order: "
for(int i = 0; i < n; i++)
cout << arr[i] << " "

delete [] arr
return 0;

}

17 Апр в 15:55
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Название заказа не должно быть пустым
Введите email
Бесплатные доработки
Гарантированные бесплатные доработки
Быстрое выполнение
Быстрое выполнение от 2 часов
Проверка работы
Проверка работы на плагиат
Интересные статьи из справочника
Поможем написать учебную работу
Название заказа не должно быть пустым
Введите email
Доверьте свою работу экспертам
Разместите заказ
Наша система отправит ваш заказ на оценку 90 792 авторам
Первые отклики появятся уже в течение 10 минут
Прямой эфир