Questions about Recursion?

maxall exercise (tail recursive case)

maxall exercise (tail recursive case)

by Adam AlBazzal -
Number of replies: 2
Picture of GroupEn

can we consider this code as a solution:

'''c

int maxall( int T[] , int size ,int m )

{

if(size==1)

{

if(m>T[0])

     return m;

return T[0];

}

return maxall(T+1,size-1,m);

}

note:i called the function maxall in the main like this:

max=maxall(anarray,15,anarray[0]);

}

In reply to Adam AlBazzal

Re: maxall exercise (tail recursive case)

by Adam AlBazzal -
Picture of GroupEn

Sorry this is the correct code

```c

int maxall( int T[] , int size ,int m )

{

if(size==1)

{

if(m>T[0])

     return m;

return T[0];

}

m=max2(T[1],m);

return maxall(T+1,size-1,m);

}

note:i called the function maxall in the main like this:

max=maxall(anarray,15,anarray[0]);

```c

In reply to Adam AlBazzal

Re: maxall exercise (tail recursive case)

by Siba Haidar -
m=max2(T[0],m);
and add also a base case for size==0