find max min in an array recursion in c

Solutions on MaxInterview for find max min in an array recursion in c by the best coders in the world

showing results for - "find max min in an array recursion in c"
Hiba
25 Mar 2017
1#include <stdio.h>
2 #include <conio.h>
3 
4 int minimum(int a[],int n,int i)
5 {
6 	static int min=0;;
7 	   if(i<n)
8       {
9       	if(a[min]>a[i])
10       	 {
11			      min=i;
12			      minimum(a,n,++i);
13			      
14        }
15	   }
16	   
17        return min;
18 	
19 }
20 int maximum(int a[],int n,int i)
21 {
22 	   	static int max=0;;
23 	   if(i<n)
24       {
25       	if(a[max]<a[i])
26       	 {
27			      max=i;
28			      maximum(a,n,++i);
29			      
30        }
31	   }
32	   
33        return max;
34 	
35 }
36int main()
37{
38    int a[1000],i,n,sum;
39   
40    printf("Enter size of the array : ");
41    scanf("%d", &n);
42 
43    printf("Enter elements in array : ");
44    for(i=0; i<n; i++)
45    {
46        scanf("%d", &a[i]);
47    }
48 
49     
50 
51     printf("minimum of array is : %d",a[(minimum(a,n,1))]);
52 
53     printf("\nmaximum of array is : %d",a[(maximum(a,n,1))]);
54 
55 
56    
57}
58