Answer to Question #292734 in C++ for Abdullah

Question #292734

Write a C++ program to find the largest element of a given array of integers.


1
Expert's answer
2022-02-01T11:59:03-0500
#include <iostream>



int find_largest(int* arr, int size)
{
    int a = 0;
    for (int i = 0; i != size; ++i)
    {
        if (arr[i] > a)
        {
            a = arr[i];
        }
    }
    return a;
}

int main() {


    int arr[] = { 1, 50, 13, 89, 116 };
    std::cout << "Largest number: " << find_largest(arr, 5) << std::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

LATEST TUTORIALS
New on Blog