Users Online

· Guests Online: 42

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to Find the Biggest Number in an Array of Numbers using Recursion

This C Program prints the largest number in an unsorted array of elements using recursion. The array used here is of type integer.

Here is the source code of the C program to print the largest number in an unsorted array. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to find the Biggest Number in an Array of Numbers using
* Recursion
*/
#include <stdio.h>

int large(int[], int, int);

int main()
{
int size;
int largest;
int list[20];
int i;

printf("Enter size of the list:");
scanf("%d", &size);
printf("Printing the list:\n");
for (i = 0; i < size ; i++)
{
list[i] = rand() % size;
printf("%d\t", 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);
}
}
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;
}
}


$ cc pgm8.c
$ a.out
Enter size of the list:8
Printing the list:
7 6 1 3 1 7 2 4
The largest number in the list is: 7

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.82 seconds
10,842,811 unique visits