WAP in C to find the Largest Number in an Array of Numbers using Recursion?

#include<stdio.h>
#include<conio.h>
int large(int[], int, int);
int main()
{
int size, largest, list[20], i;
clrscr();
printf(“Enter size of the array:”);
scanf(“%d”, &size);
printf(“Enter the elements:\n”);
for (i = 0; i < size ; i++)
{
scanf(“%d”,&list[i]);
}
if (size == 0)
{
printf(“Empty list\n”);
}
else
{
largest = list[0];
largest = large(list, size – 1, largest);
printf(“\nThe largest number in the list is: %d\n”, largest);
}

getch();

return(0);
}
int large(int list[], int size, int largest)
{
if (size == 1)
return(largest);
if (size > -1)
{
if (list[size] > largest)
{
largest = list[size];
}
return(largest = large(list, size – 1, largest));
}
else
{
return(largest);
}
}

Output:-

larnumrec.png

Advertisements