Відповідь:
C++ code:
#include <iostream>
#include <cmath>
void input_arr(double *arr,const int size){
for(int i = 0; i < size; i++){
std::cout << "arr[" << i << "]: ";
std::cin >> arr[i];
}
void print_arr(double *arr,const int size){
std::cout << arr[i] << "\t";
std::cout << std::endl;
double average(double *arr,const int size){
double aver = 0;
aver += arr[i];
return aver / size;
int count(double *arr,const int size){
double aver = average(arr,size);
int counter = 0;
if(arr[i] > aver){
counter++;
return counter;
int position_first_negative(double *arr,const int size){
int index;
if(arr[i] < 0){
index = i;
break;
return index;
double sum(double *arr,const int size){
double sum_abs = 0;
int first_negative = position_first_negative(arr,size);
if(first_negative == 0 && arr[0] > 0){
std::cout << "Negative elements is not found" << std::endl;
else{
for(int i = first_negative + 1; i < size; i++){
sum_abs += fabs(arr[i]);
return sum_abs;
int main(){
system("cls");
int size;
std::cout << "Enter a size: ";
std::cin >> size;
double *arr = new double[size];
input_arr(arr,size);
print_arr(arr,size);
std::cout << "Count elements: " << count(arr,size) << std::endl;
std::cout << "Sum abs: " << sum(arr,size) << std::endl;
delete[] arr;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Відповідь:
C++ code:
#include <iostream>
#include <cmath>
void input_arr(double *arr,const int size){
for(int i = 0; i < size; i++){
std::cout << "arr[" << i << "]: ";
std::cin >> arr[i];
}
}
void print_arr(double *arr,const int size){
for(int i = 0; i < size; i++){
std::cout << arr[i] << "\t";
}
std::cout << std::endl;
}
double average(double *arr,const int size){
double aver = 0;
for(int i = 0; i < size; i++){
aver += arr[i];
}
return aver / size;
}
int count(double *arr,const int size){
double aver = average(arr,size);
int counter = 0;
for(int i = 0; i < size; i++){
if(arr[i] > aver){
counter++;
}
}
return counter;
}
int position_first_negative(double *arr,const int size){
int index;
for(int i = 0; i < size; i++){
if(arr[i] < 0){
index = i;
break;
}
}
return index;
}
double sum(double *arr,const int size){
double sum_abs = 0;
int first_negative = position_first_negative(arr,size);
if(first_negative == 0 && arr[0] > 0){
std::cout << "Negative elements is not found" << std::endl;
}
else{
for(int i = first_negative + 1; i < size; i++){
sum_abs += fabs(arr[i]);
}
return sum_abs;
}
}
int main(){
system("cls");
int size;
std::cout << "Enter a size: ";
std::cin >> size;
double *arr = new double[size];
input_arr(arr,size);
print_arr(arr,size);
std::cout << "Count elements: " << count(arr,size) << std::endl;
std::cout << "Sum abs: " << sum(arr,size) << std::endl;
delete[] arr;
return 0;
}