Answers for "find max min in an array recursion in c"

C
0

find max min in an array recursion in c

#include <stdio.h>
 #include <conio.h>
 
 int minimum(int a[],int n,int i)
 {
 	static int min=0;;
 	   if(i<n)
       {
       	if(a[min]>a[i])
       	 {
			      min=i;
			      minimum(a,n,++i);
			      
        }
	   }
	   
        return min;
 	
 }
 int maximum(int a[],int n,int i)
 {
 	   	static int max=0;;
 	   if(i<n)
       {
       	if(a[max]<a[i])
       	 {
			      max=i;
			      maximum(a,n,++i);
			      
        }
	   }
	   
        return max;
 	
 }
int main()
{
    int a[1000],i,n,sum;
   
    printf("Enter size of the array : ");
    scanf("%d", &n);
 
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
 
     
 
     printf("minimum of array is : %d",a[(minimum(a,n,1))]);
 
     printf("\nmaximum of array is : %d",a[(maximum(a,n,1))]);
 
 
    
}
Posted by: Guest on August-07-2021

Code answers related to "find max min in an array recursion in c"

Code answers related to "C"

Browse Popular Code Answers by Language