-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMAXMIN.C
More file actions
77 lines (55 loc) · 2.5 KB
/
Copy pathMAXMIN.C
File metadata and controls
77 lines (55 loc) · 2.5 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>
#include<conio.h>
void Rmaxmin(int[],int,int,int*,int*);
void main()
{
int i,n,A[50],max,min;
clrscr();
printf("Enter the num of elements : ");
scanf("%d",&n);
printf("Enter the elements.....\n");
for(i=0;i<n;i++)
scanf("%d",&A[i]);
Rmaxmin(A,0,n-1,&max,&min);
printf("MAximum element : %d\n",max);
printf("Minimum element : %d",min);
getch();
}
void Rmaxmin(int A[50],int low,int high,int *fmax,int *fmin)
{
int mid ,hmax,hmin;
if(low==high)
*fmax=*fmin=A[low];
else
if(low==high-1)
if(A[low]>A[high])
{
*fmax=A[low];
*fmin=A[high];
}
else
{
*fmax=A[high];
*fmin=A[low];
}
else
{
mid=(high+low)/2;
Rmaxmin(A,low,mid,&hmax,&hmin);
Rmaxmin(A,mid+1,high,fmax,fmin);
*fmax=(hmax>*fmax)?hmax:*fmax;
*fmin=(hmin<*fmin)?hmin:*fmin;
}
}
OUTPUT :
Enter the num of elements : 7
Enter the elements.....
56
234
90
-22
45
11
99
MAximum element : 234
Minimum element : -22