-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_MAX.cpp
58 lines (48 loc) · 963 Bytes
/
01_MAX.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stdio.h>
#include<conio.h>
int maxmin(int a[],int left,int right, int &max,int &min)
{
int max1,min1,mid;
if(left==right)
max=min=a[left];
else if(left==right-1)
{
if(a[left]>a[right])
{
max=a[left];
min=a[right];
}
else
{
max=a[right];
min=a[left];
}
}
else
{
mid=(left+right)/2;
maxmin(a,left,mid,max,min);
maxmin(a,mid+1,right,max1,min1);
if(max1>max)
max=max1;
if(min1<min)
min=min1;
}
return 0;
}
int main()
{
int a[20],i,n,max,min;
printf("Enter how many number: ");
scanf("%d",&n);
printf("Enter one after another....\n");
for(i=0;i<n;i++)
{
printf("%d. ",i+1);
scanf("%d",&a[i]);
}
maxmin(a,0,n-1,max,min);
printf("\nMaximum=%d",max);
printf("\nMinimum=%d",min);
return 0;
}