C++ Program to Find Maximum and Minimum from Array

Write C++ Program to Find Maximum and Minimum from Array

// CPP Program to Find Maximum and Minimum from Array

#include <iostream>

using namespace std;

int main()
{
	int A[10] = {10, 98, 2, 3, 41, 5, 6, 17, 0, 94}, i;
	int Min, Max;

	cout << "Array Elements :--> ";
	for(i=0; i<10; i++)
    {
        cout << A[i] << " ";
    }

	Min = Max = A[0];
	int n = sizeof(A)/sizeof(A[0]);

	for(i = 0;i < n; i++)
	{
		if(A[i] < Min)
		{
			Min = A[i];
		}
		if(A[i] > Max)
		{
			Max = A[i];
		}
	}


	cout << "\n\nThe minimum element is :--> " << Min;
	cout << "\nThe maximum element is :--> " << Max;
	return 0;
}

Output:

Array Elements :--> 10  98  2  3  41  5  6  17  0  94

The minimum element is :--> 0
The maximum element is :--> 98

≪ Previous | Next ≫