Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to find the biggest number in an array of numbers using recursion in C

2 Answers

0 votes
#include <stdio.h>

int find_biggest_recursion(int arr[], int i, int biggest) {
    if (i == 0)
        return biggest;
    if (i > 0) {
        if (arr[i] > biggest) {
            biggest = arr[i];
        }
        return find_biggest_recursion(arr, i - 1, biggest);
    }
}

int main(void) {
    int arr[] = { 4, 7, 90, 20, 10, 8, 89, 40, 55, 77 };

    int size = sizeof(arr) / sizeof(int);

    int biggest = arr[0];

    biggest = find_biggest_recursion(arr, size - 1, biggest);

    printf("Biggest = %d\n", biggest);

    return 0;
}




/*
run:

Biggest = 90

*/

 



answered Jan 16, 2021 by avibootz
edited May 19, 2023 by avibootz
0 votes
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int find_biggest_recursion(int* arr, int n) {
	if (n == 0)
		return INT_MIN;
	
	return max(arr[n - 1], find_biggest_recursion(arr, n - 1));
}

int main()
{
	int arr[] = { 3, 9, 17, 5, 0, 8, 12, 10, 16, 15  };

	int size = sizeof(arr) / sizeof(int);

	int biggest = find_biggest_recursion(arr, size);

	printf("Biggest = %d\n", biggest);

	return 0;
}



/*
run:

Biggest = 17

*/

 



answered May 19, 2023 by avibootz

Related questions

...