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
a. Find an algorithm for solving the following problem: Given a positive integer n, find the...
a. Find an algorithm for solving the following problem: Given a positive integer n, find the list of positive integers whose product is the largest among all the lists of positive integers whose sum is n. For example, if n is 4, the desired list is 2, 2 because 2 × 2 is larger than 1 × 1 × 1 × 1, 2 × 1 × 1, and 3 × 1. If n is 5, the desired list is 2,...
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.
question: Complete the function remove number such that given a list of integers and an integer...
question: Complete the function remove number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. please edit the Python form without errors def remove_number(lst: List[int], number: int) -> None:     """         Remove every instance of number in lst. Do this         *in-place*, i.e. *modify* the list. Do NOT         return a new list....
(Greatest Common Divisor) The greatest common divisor (GCD) of two integers is the largest integer that...
(Greatest Common Divisor) The greatest common divisor (GCD) of two integers is the largest integer that evenly divides each of the numbers. Write a JAVA program that returns the greatest common divisor of two integers.
design an algorithm in a c++ function that takes as input a list of n integers...
design an algorithm in a c++ function that takes as input a list of n integers and find the location of the last even integer in the list or returns 0 if there are no even integers in the list
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
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...
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)