a. Write, compile, and run a C++ program to input 10 integer numbers into an arr
ID: 3646558 • Letter: A
Question
a. Write, compile, and run a C++ program to input 10 integer numbers into anarray named fmax and determine the maximum value entered. Your program should contain
only one loop, and the maximum should be determined as array element values are being
input. (Hint: Set the maximum equal to the first array element, which should be input before
the loop used to input the remaining array values.)
b. Repeat Exercise a, keeping track of both the maximum element in the array and the index
number for the maximum. After displaying the numbers, display these two messages
(replacing the underlines with the correct values):
The maximum value is: ____
This is element number ___ in the list of numbers
Part a & b:
********************************************************
#include <iostream>
using namespace std;
int main()
{
int index = 0, nb = 0;
int arr [10];
for ( int i = 0; i < 10; i++)
{
cout << "Type an integer: ";
cin >> arr[i];
if (arr[i] > nb)
{
nb = arr[i];
index = i;
}
}
cout <<" The maximum value is:"<<nb<<endl;
cout<<" This is element number "<<index<<" in the list of numbers"<<endl;
return 0;
}
********************************************************
c. Repeat Exercise (b), but have your program locate the minimum value of the data entered.
?
Explanation / Answer
#include using namespace std; const int MINNUM = 10; int findMin(int [MINNUM]); int main() { int nums[MINNUM] = {2, 18, 1, 27, 16,18, 5, 7, -45, 45}; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.