Minimum and Maximum Element of Array in C++

C++ program to print the minimum and maximum element of the array. Using this program we can easily find the size of the array’s min and max elements. A data structure that contains a group of elements is known as an array. These items are often all of the same data type, such as an integer or a string. In computer programs, arrays are widely used to organize data so that a related group of numbers can be readily sorted or searched.

#include <iostream>
using namespace std;
int main()
int array[500], *max, *min, size, i;
cout<<"Enter the size of an array\n";
cout<<"Enter array elements\n";
for ( i = 0 ; i < size ; i++ )
max = array;
min = array;
for (i = 0; i < size; i++)
if (*(array+i) > *max)
*max = *(array+i);
cout<<"Maximum element in the array is "<< *max << "\n" ;
for (i = 0; i < size; i++)
if (*(array+i) < *min)
*min = *(array+i);
cout<<"Minimum element in the array is"<< *min <<"\n";
return 0;



Enter the size of an array
Enter array elements
Maximum element in the array is 78
Minimum element in the array is34

DIfference between min and max function in c++ program

The min() function is an algorithm header library function that is used to determine the smallest value from two values. It accepts two values and returns the smallest value, or the first value if both values are the same.

max Algorithm in C++ () In C++, the max() function can be used in three ways: It compares the two parameterized values and returns the greater of the two. If they’re both equal, the first is returned.

What is array in c++ programming

An array is a data structure that can hold a fixed number of elements of the same data type in a fixed size. Although an array is used to hold data, it is often more beneficial to conceive of it as a collection of variables of the same type.

Similar Programs