Search the Largest Element in an Array of Integers using recursion - C Function

C examples for Function:Recursive Function

Description

Search the Largest Element in an Array of Integers using recursion

Demo Code

#include <stdio.h>

int largest(int xList[], int low, int up);

int main(){//ww w . jav a2s  .c  o m
    int counter = 5, i, myList[15];

    printf("Enter %d Elements : ", counter);

    for (i = 0; i < counter; i++)
      scanf("%d", &myList[i]);

    printf("The largest element in array: %d",
    largest(myList, 0, (counter-1)));

    return 0;
}

int largest(int xList[], int low, int up)
{
    int max;
    if (low == up)
        return xList[low];
    else
    {
        max = largest(xList, low + 1, up);
        if (xList[low] >= max)
            return xList[low];
        else
            return max;
    }
}

Related Tutorials