Can anyone help me fix the problem with the code for finding max-min in an array?
Code:#include<stdio.h> #include<conio.h> maxmin(int,int,int,int); int num[20],max,min,max1,min1; main() { int n,i; printf("enter number of elements in the array\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the number\n"); scanf("%d",&num[i]); } maxmin(0,n-1,max,min); printf("the maximum element is- %d\n",max); printf("the minimum element is- %d\n",min); getch(); } maxmin(int i,int j,int max,int min) { if(i=j) max=min=num[i]; else if(j=i+1) { if(num[i]<num[j]) { max=num[j]; min=num[i];} else if(num[i]>num[j]){max=num[i]; min=num[j];} else max=min=num[i]; } else { int mid=(i+j)/2; maxmin(i,mid,max,min); maxmin(mid+1,j,max1,min1); }Code:if(max<max1) max=max1; if(min>min1) min=min1; }



11Likes
LinkBack URL
About LinkBacks




