Question

In: Computer Science

Write C++ program to do the following: 1. Create integer array size of 10 2. Ask...

Write C++ program to do the following:
1. Create integer array size of 10
2. Ask user input the values of the array's element using for loop
3. pass the array to void function. in void function do the following:
a. Find the maximum of the array.
b. Compute the element average
c. Find out how many numbers are above the average
d. Find out and print how many numbers are below the average
e. find out how many numbers are equal to he average.

Solutions

Expert Solution


#include<iostream>
using namespace std;
void fun(int InputNum[])
{
float maxi=InputNum[0];
int above_avg_cnt=0;
int below_avg_cnt=0;
int equal_avg_cnt=0;
//find max
float sum=0;
for(int i=0;i<10;i++)
{
if(maxi<InputNum[i])
maxi=InputNum[i];

sum+=InputNum[i];
}
float avg=sum/10;


for(int i=0;i<10;i++)
{
if(InputNum[i]>avg)
above_avg_cnt++;
if(InputNum[i]<avg)
below_avg_cnt++;
if(InputNum[i]==avg)
equal_avg_cnt++;
}
cout<<"Maximum of the array is: "<<maxi<<endl;
cout<<"Average of the array is: "<<avg<<endl;
cout<<"element above the average: "<<above_avg_cnt<<endl;
cout<<"element below the average: "<<below_avg_cnt<<endl;
cout<<"element equal to the average: "<<equal_avg_cnt<<endl;

}

int main()
{
int n=10;
int arr[n];
cout<<"Enter 10 element: ";
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
fun(arr);

}


Related Solutions

Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
Write a program in c++ to do the following: 2. Create an array to hold up...
Write a program in c++ to do the following: 2. Create an array to hold up to 20 integers. 3. Create a data file or download attached text file (twenty_numbers.txt) that contains UP TO 20 integers. 4. Request the input and output file names from the user. Open the files being sure to check the file state. 5. Request from the user HOW MANY numbers to read from the data file, up to twenty. Request the number until the user...
c++ language Create a file program that reads an int type Array size 10; the array...
c++ language Create a file program that reads an int type Array size 10; the array has already 10 numbers, but your job is to resize the array, copy old elements of array to the new one and make it user input and add an additional 5 slots in the array, and lastly do binary search based on user input. close the file.
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
Write a program to reverse each integer number on array (size 3) using while loop. C++...
Write a program to reverse each integer number on array (size 3) using while loop. C++ Input: 3678 2390 1783 Output: 8763 0932 3871
1- Write it with C++ program §Write a function Rotate that rotates an array of size...
1- Write it with C++ program §Write a function Rotate that rotates an array of size n by d elements to the left §Use array as argument §In the main function, call the function Rotate and show the rotated array §Test your code For example: Input: [1 2 3 4 5 6 7], n = 7, d = 2 Output: [3 4 5 6 7 1 2] 2- Write it in C++ §Search Insert Position •Given a sorted array in...
c++ Write a program that will ask the user for three pairs of integer values. The...
c++ Write a program that will ask the user for three pairs of integer values. The program will then display whether the first number of the pair is multiple of the second. The actual work of making the determination will be performed by a function called IsMultiple that takes two integer arguments (say, x and y). The function will return a Boolean result of whether x is a multiple of y.
Create the following functions for an array in C++. Test with size 10, 10,000 and 100,000....
Create the following functions for an array in C++. Test with size 10, 10,000 and 100,000. Time each sort. Merge sort Insertion Sort Selection Sort         Bubble Sort Quick Sort PLEASE DO IT IN C++
Write a program to do the following. • Input an integer n. • Create a BST...
Write a program to do the following. • Input an integer n. • Create a BST S inserting the keys 1, 2, . . . , n in that order, which will result in a completely-skewed tree. • Measure the time to search for n + 1 in S. • Display the time taken for search. /** * Exception class for access in empty containers * such as stacks, queues, and priority queues. * @author Mark Allen Weiss */ public...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT