Question

In: Computer Science

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.

Solutions

Expert Solution

Answer:

C++ program:

#include<iostream>
#include<numeric>
using namespace std;
int main()
{
   int arr[10],sum=0,i,count=0; //initializing the variables
   float average; // initializing the average as float data type
   int n=10; //size of array taken as 10 that is given in question
   for(i=0;i<n;i++) //using for loop for taking the array elements
   {
       cout<< "\n Enter your "<< i+1 <<" integer: ";// asking user for array element
       cin>>arr[i]; // storing in array
       sum= sum+arr[i]; // finding sum of array elements
   }
   average = sum/n; // finding average of array elements
   cout<< "The average of the array elements: " <<average <<"\n\n"; // printing average
   for(i=0;i<n;i++) // for loop for counting the elements below average
   {
       if(arr[i]<average) // checking the elements whether it is below or not
       {
           count=count+1; //counting
       }
   }
   cout<< "Number of elements below the avarage are: " <<count; // printing the number of elements below average
}

Output:


Related Solutions

Q#1 Write a C++ program that reads n integer values and stores them in an array...
Q#1 Write a C++ program that reads n integer values and stores them in an array of maximum 20 integers. Read from the user a valid value of n (n should not exceed 20). After reading the n array elements find the maximum and minimum elements. 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...
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])...
C++ Language Write a program that reads the numbers.txt file and stores it into an array...
C++ Language Write a program that reads the numbers.txt file and stores it into an array of integers. Use the sample functions in the text and in the notes from chapter 8 to sort the array in ascending order (low to high). You can use either method (bubble or selection sort) to accomplish this. Then store the sorted array into an output file sorted Numbers.txt. There are 100 values both positive and negative integers in this file.
The Sum and The Average In C++, Write a program that reads in 10 integer numbers....
The Sum and The Average In C++, Write a program that reads in 10 integer numbers. Your program should do the following things: Use a Do statement Determine the number positive or negative Count the numbers of positive numbers, and negative Outputs the sum of: all the numbers greater than zero all the numbers less than zero (which will be a negative number or zero) all the numbers Calculate the average of all the numbers. The user enters the ten...
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
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...
Write a C program that asks the user to enter 15 integer numbers and then store them in the array.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
Write a C program that reads an integer value. Assume it is the number of a...
Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT