max() function for valarray in C++ Last Updated : 23 Oct, 2018 Comments Improve Suggest changes Like Article Like Report The max() function is defined in valarray header file. This function returns the largest value contained in the valarray. Syntax: T max() const; Parameter: This function doesn't accept any parameter. Returns: This function returns the maximum value in the valarray. Below programs illustrate the above function: Example 1:- CPP // C++ program to demonstrate // example of max() function. #include <bits/stdc++.h> using namespace std; int main() { // Initializing valarray valarray<int> varr = { 3, 2, 1, 4, 5 }; // Displaying maximum element of valarray cout << "The largest element of valarray is = "; cout << varr.max() << endl; return 0; } Output: The largest element of valarray is = 5 Example 2:- CPP // C++ program to demonstrate // example of max() function. #include <bits/stdc++.h> using namespace std; int main() { // Initializing valarray valarray<int> varr = { 22, 24, 36, 42, 12 }; // Displaying maximum element of valarray cout << "The largest element of valarray is = "; cout << varr.max() << endl; return 0; } Output: The largest element of valarray is = 42 Comment More infoAdvertise with us Next Article max() function for valarray in C++ bansal_rtk_ Follow Improve Article Tags : Misc C++ Programs C++ CPP-Functions cpp-valarray +1 More Practice Tags : CPPMisc Similar Reads valarray size() function in C++ The size() function is defined in valarray header file. This function is used to find the size of valarray and returns the size of valarray. Syntax: size_t size() const; Parameter: This function doesn't takes any parameter. Returns: This function returns the number of element in valarray. Below prog 1 min read valarray resize() function in C++ The resize() function is defined in valarray header file. This function resizes the valarray to contain n elements and assigns value to each element.Syntax: void resize( size_t n, T value = T() ); Parameter: This method accepts two parameters: n: It represents the new size of valarray.value: It repr 2 min read valarray min() in C++ The min() function is defined in valarray header file. This function returns the smallest value contained in the valarray. Syntax: T min() const; Returns: This function returns the minimum value in the valarray. Below programs illustrate the above function: Example 1:- CPP // C++ program to demonstr 1 min read valarray sum() in C++ The sum() function is defined in valarray header file. This function returns the sum of all the elements in the valarray, as if calculated by applying operator+= to a copy of one element and all the other elements, in an unspecified order. Syntax: T sum() const; Returns: This function returns the su 1 min read How to Create a Function Template in C++? In C++, templates enable us to write generic programs that handle any data type. We can create a template class, function, and variable. A template function is a function that can work with any data type. In this article, we will learn how to create a function template in C++. Create a Function Temp 2 min read Maximum value of unsigned int in C++ In this article, we will discuss the maximum value of unsigned int in C++. Unsigned int data type in C++ is used to store 32-bit integers.The keyword unsigned is a data type specifier, which only represents non-negative integers i.e. positive numbers and zero. Some properties of the unsigned int dat 2 min read C++ - Finding Maximum Value in Image using OpenCV Suppose you have an image stored in a matrix in C++ and you want to find the maximum value among all the pixels in the image. The matrix may be of any type, such as 'uchar' (for 8-bit unsigned integers, which are commonly used to represent pixels in an image), 'int', or 'float'. Your task is to writ 4 min read C++ Program to Find maximum element of each row in a matrix Given a matrix, the task is to find the maximum element of each row. Examples: Input : [1, 2, 3] [1, 4, 9] [76, 34, 21] Output : 3 9 76 Input : [1, 2, 3, 21] [12, 1, 65, 9] [1, 56, 34, 2] Output : 21 65 56 Approach : The approach is very simple. The idea is to run the loop for no_of_rows. Check each 2 min read C++ Program for Maximum and Minimum in a square matrix. Given a square matrix of order n*n, find the maximum and minimum from the matrix given. Examples: Input : arr[][] = {5, 4, 9, 2, 0, 6, 3, 1, 8}; Output : Maximum = 9, Minimum = 0 Input : arr[][] = {-5, 3, 2, 4}; Output : Maximum = 4, Minimum = -5 Naive Method : We find maximum and minimum of matrix 3 min read C++ Program to Find Largest Element in an Array In this article, we will learn to write a C++ program to find the largest element in the given array arr of size N. The element that is greater than all other elements is the largest element in the array. Recommended PracticeHelp a Thief!!!Try It! One of the most simplest and basic approaches to fin 2 min read Like