Answer to Question #337709 in C++ for Arr 5.11111

Question #337709

Input a random positive integer. Then create an integer array that has a size equal to the inputted integer.


Using a loop, add random integer values into the array one by one. The number of values to be stored is dependent on the inputted positive integer given in the first instruction.


Print out the largest integer among all the elements on the array, by any means necessary.


Input



The first line contains the size of the array.


The next lines contains an integer.



5


5


34


3


23


10

1
Expert's answer
2022-05-05T14:02:22-0400
#include<iostream>

using namespace std;

int main()
{
	int sz;
	cout << "Please, enter size of an array: ";
	cin >> sz;
	int* arr = new int[sz];
	cout << "Please, enter values: ";
	for (int i = 0; i < sz; i++)
	{
		cin >> arr[i];
	}
	int larg = arr[0];
	for (int i = 0; i < sz; i++)
	{
		if (arr[i] > larg)
		{
			larg = arr[i];
		}
	}
	cout << "The largest value is " << larg;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS