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
#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;
}
Comments
Leave a comment