Site icon T4Tutorials.com

C++ program to find maximum and minimum element in array

C++ program to find maximum and minimum element in the array.

Write a C++ program to input elements in an array from the user and then find the minimum and maximum element in an array.

C++ program to find the biggest and smallest elements in an array. C++ program to find the biggest and smallest number in an array. Logic to find maximum and minimum elements in an array in C programming.

#include<iostream>
using namespace std;
#define size10
int main()
{
	int arr[10];
	int i,max,min;
	cout<<"PLease enter elements in the array?";
	for(i=0;i<10;i++)
	{
		cin>>arr[i];
	}
	max=arr[0];
	min=arr[0];
	for(i=1;i<10;i++)
	{
		if(arr[i]>max)
		{
			max=arr[i];
		}
		if(arr[i]<min)
		{
			min=arr[i];
		}
	}
	cout<<"maximum number is"<<max<<endl<<"minimum number is"<<min;
}

Output

C++ program to find biggest and smallest elements in an array

YouTube video player

Exit mobile version