max min reference

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
684 B
3
Indexable
Never
#include<stdio.h>

int a[10],n;

int maxmin(int i,int j,int *max, int *min){
 int max1,min1,mid;
 if(i==j){
  *max=a[i];
  *min=a[i];
 }
 else if(i==j-1){
  if(a[i]>a[j]){
  *max=a[i];
  *min=a[j];   
  }
  else{
  *max=a[j];
  *min=a[i];
  }
 }
 else{
  mid=(i+j)/2;
  maxmin(i,mid,max,min);
  max1=*max;
  min1=*min;
  maxmin(mid+1,j,max,min);
  if(max1>*max)
  *max=max1;
  if(min1<*min)
  *min=min1;
 }
}
int main(){
 int i,s,mid,max,min;
 printf("Enter array size: ");
 scanf("%d",&n);
 printf("Enter elements in array: \n");
 
 for(i=0;i<n;i++){
  scanf("%d",&a[i]);
 }
 maxmin(0,n-1,&max,&min);
 printf("Max= %d\nMin=%d",&max,&min);
}