Question

Given a list of n integers, find the largest integer in the list. Use Java or...

Given a list of n integers, find the largest integer in the list. Use Java or C++ please

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Devise an algorithm that takes a list of n > 1 integers and finds the largest...
Devise an algorithm that takes a list of n > 1 integers and finds the largest and smallest values in the list.
1). Describe an algorithm that takes a list of n integers a1,a2,...,an and find the average...
1). Describe an algorithm that takes a list of n integers a1,a2,...,an and find the average of the largest and smallest integers in the list.
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
JAVA QUESTION: A singly linked list method that will: -A method that will find the largest...
JAVA QUESTION: A singly linked list method that will: -A method that will find the largest number in the list -A method that will find the smallest number in the list THESE ARE TWO SEPARATE BASIC METHODS
1. Let n be an odd positive integer. Consider a list of n consecutive integers. Show...
1. Let n be an odd positive integer. Consider a list of n consecutive integers. Show that the average is the middle number (that is the number in the middle of the list when they are arranged in an increasing order). What is the average when n is an even positive integer instead? 2. Let x1,x2,...,xn be a list of numbers, and let ¯ x be the average of the list.Which of the following statements must be true? There might...
Describe an algorithm that takes as input a list of n integers and finds the location...
Describe an algorithm that takes as input a list of n integers and finds the location of the first even integer or returns -1 if there is no even integer in the list. Here is the operation's header: procedure locationOfFirstEven(a1, a2, a3, ..., an : integers)
Give an algorithm for finding the second largest integer in a finite sequence of integers. Write...
Give an algorithm for finding the second largest integer in a finite sequence of integers. Write the algorithm in pseudocode format
In JAVA: Write a program that reads an integer, a list of words, and a character....
In JAVA: Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle...
Describe an algorithm that, given a set S of n integers and another integer x, determines...
Describe an algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. Your algorithm must be nlogn. Evaluate how long each step in the algorithm takes to demonstrate that it meets this requirement.
Use the Euclidean Algorithm to find the smallest nonnegative integer x, s.t. there exists integers k_1,...
Use the Euclidean Algorithm to find the smallest nonnegative integer x, s.t. there exists integers k_1, k_2, such that x = 11k_1 + 3 and x = 49k_2 + 5.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT