Given a list of n integers, find the largest integer in the list. Use Java or C++ please
#include <iostream> using namespace std; int main() { int n; cout << "How many numbers: "; cin >> n; // read value of n int *list = new int[n]; // create a list // read list from user cout << "Enter " << n << " integers: "; for (int i = 0; i < n; ++i) { cin >> list[i]; } // find max element in the list int max = list[0]; for (int i = 0; i < n; ++i) { if (list[i] > max) max = list[i]; } // print the result cout << "Largest integer in the list is " << max << endl; delete[] list; return 0; }
Get Answers For Free
Most questions answered within 1 hours.