In C++ Write a correct and complete C++ program that inputs 20 integer values fr
ID: 3582909 • Letter: I
Question
In C++
Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray (), which takes two arguments and reverses the order of the numbers. That is, for example, if the input numbers were 5,3,7, then reverseArry would change the order to 7,3 ,5. Include a final sub-function named printArray (), which takes two arguments and prints the array. Assumptions to be made: you do not have to check errors in the input values, i.e., all input values can be stored as type int.
Show the output
Explanation / Answer
In programming, operate refers to a section that teams code to perform a particular task.
Depending on whether or not a operate is predefined or created by programmer; there area unit 2 forms of function:
Library operate
User-defined operate
Library operates area unit the intrinsical function in C++ programming.
Programmer will use library operate by invoking operate directly; they do not have to be compelled to write it themselves.
#include <iostream>
#include <cmath>
using namespace std;
int main()
range, squareRoot;
cout << "Enter a number: ";
cin >> number;
// sqrt() can be a library work to determine origin
squareRoot = sqrt(number);
cout << "Square root of " << variety << " = " << squareRoot;
return 0;
}
Output
Enter a number: twenty six
Square root of twenty six = five.09902
In the example higher than, sqrt() library operate is invoked to calculate the root of variety.
Notice code #include <cmath> within the higher than program. Here, cmath could be a header file. The operate definition of sqrt()(body of that function) is gift within the cmath header file.
You can use all functions outlined in cmath once you embrace the content of file cmath during this program victimisation #include <cmath> .
Every valid C++ program has a minimum of one operate, that is, main() operate.