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,943 questions

51,884 answers

573 users

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

1 Answer

0 votes
#include <stdio.h>
 
int find_smallest_recursion(int arr[], int i, int smallest) {
    if (i == 0) {
        return smallest;
    }
    if (i > 0) {
        if (arr[i] < smallest) {
            smallest = arr[i];
        }
        return find_smallest_recursion(arr, i - 1, smallest);
    }
}
 
int main(void) {
    int arr[] = { 7, 90, 20, 10, 8, 89, 4, 70, 55, 84 };
 
    int size = sizeof(arr) / sizeof(int);
 
    int smallest = arr[0];
 
    smallest = find_smallest_recursion(arr, size - 1, smallest);
 
    printf("Smallest = %d\n", smallest);
 
    return 0;
}


 
 
/*
run:
 
Smallest = 4
 
*/

 



answered Jun 1, 2024 by avibootz

Related questions

2 answers 195 views
1 answer 147 views
2 answers 193 views
1 answer 177 views
1 answer 214 views
...