Answer to Question #215119 in C++ for ‪Hussein Saleh el

Question #215119
We are dealing with a 1D array of n integer values.
1. Write a function called InputArray that inputs an array of integers.
2. Write a function called OutputArray that outputs an array of integers, where each integer
should appear on a different line.
3. Write a function called Minx that receives an array of integers and returns the minimum
value in it.
4. Write a function called Avx that receives an array of integers and returns the average of
its values.
5. Write a function called CountAv that receives an array of integers and returns the count
of repetition of the values that are 1 unit far from the average at maximum.
Example: In [3 2 4 5 1 3], the average is 3 and the numbers that are only 1 unit far are 3, 2, and 4.
There count is 4. You can use two functions
1
Expert's answer
2021-07-08T02:38:28-0400
#include<iostream>
#include<array>
using namespace std;
#define N 5
void InputArray(){
	int arr[10];
	cout<<"Enter the elements of the array\n";
	for(int i=0; i<10; i++){
		cout<<"Enter element\t"<<(i+1);
		cin>>arr[i];
	}
 
}
void  OutputArray(){
	int arr[10];
	cout<<"The array elements are\n";
 for(int i=0; i<10; i++){
		cout<<arr[i]<<"\n";
	
	}
}
int  Minx(int arr[3]){
int min = arr[0];
for(int i=0; i<3; i++){
	if(min > arr[i]){
		min = arr[i];
	}
}
return min;	
}
int Avx(int arr[N]){
	float sum = 0.0;
	for(int i=0; i<N; i++){
		sum +=arr[i];
	}
	return sum/N;
}
int CountAv(int arr[6]){
	int count = 0;
	int average  = Avx(arr);
	for(int i=0; i<6; i++){
		if((average == arr[i] - 1) ||( average == arr[i] + 1 || average==arr[i])){
			count += 1;
		}
	}
	return count;
}




int main(){
int arr1[6]={3,2, 4, 5, 1, 3};
cout<<CountAv(arr1)<<"\n";
	int arr[3] = {8,9,2};
	cout<<Minx(arr);
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS