6)
//return the maximum of integers x and y.
int max(int x, int y)
{
return x>y?x:y;
}
// find the maximum value in the n- element.
//integer array a.
int arraymax(int a[], int n)
{
//in a one element array the maximum is a[0]
//stopping condition.
if(n==1)
return a[0];
else
//recursive step, find the maximum of a[n-1] and
//arraymax(a, n-1)
return max(arraymax(a, n-1),a[n-1]);
}
9)
//determine if the string is a palindrome. s is the starting index and e is
// the ending index.
int pal(char A[], int s, int e)
{
// if s and e are equal, A is a palindrome. This is the stopping condition.
if(s>=e)
return 1;
else
//if A[s] and A[e] are not equal A is not a palindrome.
if(A[s]!= A[e])
return 0;
else
// test the string between indices s+1 and e-1
return pal(A, s+1, e-1)
}
11)
//recursively computes the GCD of m and n.
int gcd(int a, int b)
{
int remainder= a%b;
if (remainder==0)
return b;
else
return gcd(b, remainder);
}