Find biggest number in an array of numbers using recursion.
Implementation:
#include <stdio.h>
#include <stdlib.h>
/* function to find the largest number from the array */
int findbiggest(int *a,int i,int n)
{
static int max=0;
if(i==n)
return max;
if(*(a+i)>max)
max=*(a+i);
return findbiggest(a,i+1,n);
}
int main(void) {
int *a,i,n;
/* allocate memory for the array */
a=(int*)malloc(sizeof(int)*100);
/* get the number of elements */
scanf("%d",&n);
/* get the numbers from the user */
for(i=0;i<n;i++)
scanf("%d",(a+i));
/* print the largest number returned by the function findbiggest */
printf("%d",findbiggest(a,0,n));
return 0;
}