How to Find the Range of Values in a 2D Array in C++? Last Updated : 28 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, 2D arrays are also known as a matrix, and the range of numbers in a 2D array means the maximum and the minimum value in which the numbers lie in the given 2D array. In this article, we will learn how to find the range of numbers in a 2D array in C++. For Example, Input: my2DArray= {{80, 90, 100}, {40, 50, 60}, {10, 20, 30}};Output: The Range of numbers in the 2D array: [10 to 100]Range of Values in a 2D Array in C++To find the range of numbers in a 2D array in C++, we need to find the minimum and the maximum elements present in the 2D array. For that, we can use the std::min_element() and the std::max_element() methods provided by the STL library in C++ that returns the pointer to the smallest and largest value in the given range. C++ Program to Find the Range of Values in a 2D Array in C++The below example demonstrates how we can find the range of the numbers in a 2D array in C++. C++ // C++ program to find the range of numbers in a 2D array #include <algorithm> #include <iostream> using namespace std; // define the dimensions for the 2D array #define ROW 3 #define COL 3 int main() { // Initialize a 2D array int arr[ROW][COL] = { { 80, 90, 100 }, { 40, 50, 60 }, { 10, 20, 30 } }; // Find the minimum and maximum element of the 2D array // to determine the range of numbers int min_val = *min_element(&arr[0][0], &arr[0][0] + ROW * COL); int max_val = *max_element(&arr[0][0], &arr[0][0] + ROW * COL); // Print the range of numbers in the 2D array cout << "The Range of numbers in the 2D array: [" << min_val << " to " << max_val << "]"; return 0; } OutputThe Range of numbers in the 2D array: [10 to 100]Time Complexity: O(N * M) where N is the number of rows and M is the number of columns.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Find the Range of Values in a 2D Array in C++? M maha123 Follow Improve Article Tags : C++ Programs C++ cpp-array C++ Array Programs CPP Examples +1 More Practice Tags : CPP Similar Reads How to Find the Mode in a 2D Array in C++? A mode is a number that occurs most frequently in comparison to other numbers in a given dataset. In this article, we will find the mode in a 2D array of integers in C++. Input:myArray = { {1, 2, 2, 3}, {3, 4, 5, 5}, {5, 6, 7, 8} }Output: 5Mode in 2D ArrayTo find a mode of numbers in a 2D array, we 2 min read How to Find the Range of Numbers in an Array in C++? The range of numbers in an array means the difference between the maximum value and the minimum value in the given array. In this article, we will learn how to find the range of numbers in an array in C++. For Example, Input: myArray = {5,10,15,30,25}; Output: Range: 25Range Within an Array in C++To 2 min read How to Find the Median of 2D Array in C++? The median can be defined as the middle element of a sorted array in the case of an odd number of elements in an array and the average of the middle two elements when the number of elements in an array is even. In this article, we will see how to calculate the median of a 2D array in C++. Example: I 3 min read How to Find the Mode in a Sorted Array in C++? The mode of the given numbers can be defined as the value that occurs the most in the given dataset or the value with the highest frequency. In this article, we will discuss how to calculate the mode of the numbers in a sorted array in C++. Example: Input: myVector = {1, 2, 2, 3, 3, 3, 4, 4, 5} Outp 3 min read How to Find the Variance of Numbers in 2D Array in C++? The variance of numbers is a measure of the spread of a set of values which is used to find how much the values in a dataset differ from mean or average. In this article, we will learn how to find the variance of numbers in a 2D array in C++. Example Input: myMatrix = { { 10, 20, 30 }, { 40, 50, 60 3 min read How to Find the Smallest Number in an Array in C++? In C++, arrays are the data types that store the collection of the elements of other data types such as int, float, etc. In this article, we will learn how to find the smallest number in an array using C++. For Example,Input: myVector = {10, 3, 10, 7, 1, 5, 4} Output: Smallest Number = 1Find the Sma 2 min read How to Find Largest Number in an Array in C++? In C++, arrays are used to store the collection of similar elements to be stored in adjacent memory locations. They can store data of any type such as int, char, float, etc. In this article, we will learn how to find the largest number in an array in C++. For Example,Input: myVector = {1, 3, 10, 7, 2 min read How to Find the Product of 2D Array Elements in C++? In C++, finding the product of all elements in a 2D array means for a given 2D array of order M*N we have to multiply all the elements together. In this article, we will learn how to find the product of elements in a 2D array in C++. Example Input:myArray[2][2] = {{1, 2}, {3, 4}};Output:Product of E 2 min read How to Find the Second Smallest Element in an Array in C++? In C++, arrays are data structures that store the collection of data elements of the same type in contiguous memory locations. In this article, we will learn how to find the second smallest element in an array in C++. Example:Input:myArray = {10, 5, 8, 2, 7, 3, 15};Output:The second smallest element 3 min read How to Create a 2D Array of a Specific Size and Value in C++? In C++, a 2D array is an array of arrays that stores data in the form of a grid with rows and columns. In this article, we will learn how to create a 2D array of a specific size and fill it with some value in C++. Example Input: rows = 3; columns = 3; value = 1; Output: 2D Array: { {1, 1, 1}, {1, 1, 2 min read Like