In: Computer Science
#include<iostream>
using namespace std;
void even(int *arr,int c,int *count);
int main()
{
int c,count=0;
cout<<"Enter the size of array : ";
cin>>c;
int a[c];
cout<<"Enter the elements of array ";
for(int i=0;i<c;i++)
{
cin>>a[i];
}
even(a,c,&count);
cout<<"The even numbers between max and min is : "<<count;
}
void even(int *a,int c,int *count)
{
int max=a[0],min=a[0];
int index1=0,index2=0;
for(int i=1;i<c;i++)
{
if(a[i]<min)
{
min=a[i];
index1=i;
}
if(a[i]>max)
{
max=a[i];
index2=i;
}
}
for(int i=index1+1;i<index2;i++)
{
if(a[i]%2==0)
{
*count+=1;
}
}
}
Here is the above code which asks for the size of the array then it uses the size in order to enter the values and then passing the array,size,count to the function as pointer and the as we are using pointer there is no need to return a value as the change made can be seen in the main program which is the main use of pointer.so we directly print the count value which gives even numbers between the min and max values.
SCREENSHOT OF THE OUTPUT :