Answer to Question #290468 in C++ for mark

Question #290468

Remember that time when we've tried identifying the largest digit among the given integer? Well, let's take it to the next level, and figure out the same thing on arrays!


Let's do this one more time!



Instructions:

  1. Input a random positive integer. Then create an integer array that has a size equal to the inputted integer.
  2. 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.
  3. Print out the largest integer among all the elements on the array, by any means necessary.

IInput

The first line contains the size of the array.

The next lines contains an integer.

5
5
34
3
23
10

Output

A line containing an integer.

34
1
Expert's answer
2022-01-25T08:01:10-0500
#include <iostream>
#include <string>




using namespace std;






int main(void){
	int size;
	cout<<"Enter array size: ";
	cin>>size;
	int* numbers = new int[size];
	for (int i = 0; i < size; i++) {
		cout<<"Enter the number "<<(i+1)<<": ";
		cin>>numbers[i];
	}
	int max = numbers[0];
	for (int i = 1; i < size; i++) {
		if (numbers[i] > max) {
			max = numbers[i];
		}
	}
	cout<<"The largest integer: " << max<<"\n";




	system("pause");
	return 0;
}

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