Answer to Question #291273 in C++ for Lily

Question #291273

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.

1
Expert's answer
2022-01-27T10:47:42-0500
#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;
}

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