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++ Write a program to declare an array of double of size 25, ask the user...
C++ Write a program to declare an array of double of size 25, ask the user to input all array elements from the keyboard, then write a function named out_of_order that will test this array for the condition a[0] >= a[1] >= a[2] >= ... > a[24] The function returns a -1 if the elements are not out of order, otherwise it returns the index of the first element that is out of order. Explain what you do to avoid...
2. Write a program to do the following: • ask the user to input the size...
2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array
Q#2 Write a C++ program that reads 10 integer values and stores them in an array....
Q#2 Write a C++ program that reads 10 integer values and stores them in an array. The program should find and display the average of the array elements and how many elements are below the average.
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.
This assignment asks to create an array with 10 integer elements. Ask user to input 10...
This assignment asks to create an array with 10 integer elements. Ask user to input 10 integer values. going through all the array elements and find/print out all the prime numbers. Instructions: Only use for loops for this lab (no need to create methods or classes for this assignment). Put a comment on each line of your codes, explaining what each line of code does. basic java, please
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT