0% found this document useful (0 votes)
37 views2 pages

Num 1

This document provides code to find the largest element in an array of integers in C++. It includes the code to define a function called find_largest that takes an integer array and size as parameters and returns the largest element using max_element. It also includes a main function that defines a sample array, calls find_largest to get the largest element and prints the original array and largest element.

Uploaded by

Alemayew Azezew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Num 1

This document provides code to find the largest element in an array of integers in C++. It includes the code to define a function called find_largest that takes an integer array and size as parameters and returns the largest element using max_element. It also includes a main function that defines a sample array, calls find_largest to get the largest element and prints the original array and largest element.

Uploaded by

Alemayew Azezew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Got it!

This site uses cookies to deliver our services and to show you relevant ads. By using our site, you
acknowledge that you have read and understood our Privacy Policy. Your use of w3resource Services, is
subject to these policies More info

w3resource

C++ Exercises: Find the largest element of a given array of integers

Last update on March 18 2023 12:44:58 (UTC/GMT +8 hours)

C++ Array: Exercise-1 with Solution

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

Pictorial Presentation:

C++ Exercises: Find the largest element of a given array of integers

Sample Solution:

C++ Code :

#include<iostream>

using namespace std;

int find_largest(int nums[], int n) {

return *max_element(nums, nums + n);

int main() {
int nums[] = {

5,

4,

9,

12,

};

int n = sizeof(nums) / sizeof(nums[0]);

cout << "Original array:";

for (int i=0; i < n; i++)

cout << nums[i] <<" ";

cout << "\nLargest element of the said array: "<< find_largest(nums, n);

return 0;

You might also like