One dimensional Array.
The program will ask the user to input size of the array, and the user will input values for each index.The program will output the LARGEST inputted value and its index.
#include <iostream>
using namespace std;
int main()
{
cout << "Enter size of array: ";
int s;
cin >> s;
int* arr = new int[s];
int max;
int ind = 0;
for (int i = 0; i < s; i++) {
cout << "\nenter element by index " << i << ": ";
int e;
cin >> e;
arr[i] = e;
if (!i) max = e;
else {
if (max < e) {
max = e;
ind = i;
}
}
}
cout << "Max element: " << max << ", by index: " << ind << endl;
return 0;
}
Comments
Leave a comment