C++ program to find max and min in the array using function

#include<iostream>
using namespace std;
int arr_max_min(int arr[],int num);
int main()
{
int  num,i,arr[100],result;
cout<<“Enter the size of the arrayn”;
cin>>num;
cout<<“Enter numbers in the array one by one n”;
for(i=0;i<num;i++)
{

cin>>arr[i];
}
result=arr_max_min(arr,num);
}
int arr_max_min(int arr[],int num)
//displaying output in the function declartion part
{
int max,min,i;
max=arr[0];
for(i=0;i<num;i++)
{
if(arr[i]>max)
max=arr[i];
}
//return max; as we are already printing the output so function can not return anything
cout<<“The maximuum in the array is t”<<max;
for(i=0;i<num;i++)
{
min=arr[0];
if(arr[i]<min)
min=arr[i];
//return min;

}
cout<<“nThe minimum in the array ist”<<min;
}

OUTPUT:
Enter the size of the array
3
Enter numbers in the array one by one 
6
3
The maximuum in the array is 9
The minimum in the array is 3

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat