Skip to content

Instantly share code, notes, and snippets.

@zsrinivas
Created May 22, 2014 16:11
Show Gist options
  • Save zsrinivas/0a43e665d262fc3bbc92 to your computer and use it in GitHub Desktop.
Save zsrinivas/0a43e665d262fc3bbc92 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <math.h>
#include <stdlib.h>
#define MAXmax 100000
int findmax(int a[], int low,int high);
int findmin(int a[], int low,int high);
int main(int argc, char const *argv[])
{
int array[MAXmax];
int n,i;
scanf("%d", &n);/*n=no of elements*/
for (i = 0; i < n; ++i)
{
scanf("%d", &array[i]);
}
printf("%d\n", findmax(array,0,n-1));
printf("%d\n", findmin(array,0,n-1));
return 0;
}
int findmax(int a[], int low,int high)
{
int mid=((low+high)/2);
int pint,pont;
if (low<high)
{
pint=findmax(a,0,mid);
pont=findmax(a,mid+1,high);
return pint>pont?pint:pont;
}
else
return a[low];
}
int findmin(int a[], int low,int high)
{
int mid=((low+high)/2);
int pint,pont;
if (low<high)
{
pint=findmin(a,0,mid);
pont=findmin(a,mid+1,high);
return pint>pont?pont:pint;
}
else
return a[low];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment