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