Answer to Question #201756 in C++ for lucky

Question #201756

Write a program that asks a user to enter the size of a dynamic array that stores a list of integers. Create the dynamic array and a loop that allows the user to enter an integer value for each array element. Loop through the array, find the largest value in the array and output it, as well as its position in the array. Delete the memory allocated to your dynamic array before exiting your program


1
Expert's answer
2021-06-02T03:01:31-0400


#include <iostream>


using namespace std;


int main()
{
    int n;
	cout << "\nEnter the size of the dynamic array: ";
	cin >>n;
	int *arr = new int(n);
	int largest=arr[0];
	cout << "Enter " << n << " integers" << endl;
	for (int i= 0; i < n; i++) {
	    cout<<"\nInteger "<<i+1<<": ";
		cin >> arr[i];
	}
	for (int i= 0; i < n; i++) {
	    if (arr[i]>largest){
	        largest=arr[i];
	    }
	}
	cout<<"\nThe largest value in the array is: "<<largest;
	delete [] arr;
    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

LATEST TUTORIALS
New on Blog