View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12940 Members
Join this group to post and comment.
Manish Goyal
Manish Goyal • Nov 1, 2009

problem in c++ code

helo guys...I have a problem in following c++ code...I want to find largest and smallest element in an array..using recurssion..please help me
#include
#include
int max1,min1;
void maxmin(int a[],int,int,int*,int*);
int main()
{
int i,*a,n,max,min;
cout<<"Enter the no of elements"<>n;
a=new int[n];
cout<<"Enter elements"<>a[i];
}
maxmin(a,0,n-1,&max,&min);
cout<<"Maximum element"<a[finish])
        {
        *max=a[start];
        *min=a[finish];
        }
    else
        {
        *max=a[finish];
        *min=a[start];
        }
    }
else
mid=(start+finish)/2;
maxmin(a,start,mid,*&max,*&min);
maxmin(a,mid+1,finish,&max1,&min1);
if(max1>*max)
{
*max=max1;
}
if(*min>min1)
{
*min=min1;
}
}
Manish Goyal
Manish Goyal • Nov 3, 2009
Hello ceans I have solved this problem.there was small mistake..I hope most of you had tried this ..this code is for those who are unable to solve this..
#include
#include
int max1,min1;
void maxmin(int a[],int,int,int*,int*);
int main()
{
int i,*a,n,max,min;
cout<<"Enter the no of elements"<>n;
a=new int[n];
cout<<"Enter elements"<>a[i];
}
maxmin(a,0,n-1,&max,&min);
cout<<"Maximum element"<a[finish])
        {
        *max=a[start];
        *min=a[finish];
        }
    else
        {
        *max=a[finish];
        *min=a[start];
        }
    }
else
{
mid=(start+finish)/2;
maxmin(a,start,mid,*&max,*&min);
maxmin(a,mid+1,finish,&max1,&min1);
if(max1>*max)
{
*max=max1;
}
if(*min>min1)
{
*min=min1;
}
}
}

Share this content on your social channels -