Question

Write a recursive array that gives the min of an array C

Write a recursive array that gives the min of an array

C

Homework Answers

Answer #1
#include <stdio.h>

int minInArray(int arr[], int start, int end){
   if(start == end){
       return arr[start];
   }
   else{
       int min = minInArray(arr, start+1, end);
       if(min < arr[start]){
           return min;
       }
       else{
           return arr[start];
       }
   }
}

int main()
{
    int arr[] = {4,2,5,3,1,6,8,7};
    
    printf("%d",minInArray(arr,0,7));

    return 0;
}

1

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In java 1. Write a recursive algorithm to add all the elements of an array of...
In java 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C. 4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
C++ Write a recursive routine that will have a character array and an index as parameters...
C++ Write a recursive routine that will have a character array and an index as parameters and will return the count of all vowels (assume lowercase). You may assume that the index starts out at the END of the array.
Write a recursive C++ program that find the duplicate elements in an array. Your program shouldn't...
Write a recursive C++ program that find the duplicate elements in an array. Your program shouldn't use any sorting or use any additional array.
Write a recursive method that performs binary search on an array Arr and searches for a...
Write a recursive method that performs binary search on an array Arr and searches for a key k. Apply the recursive method to the following array: 13 | 20 | 22 | 26 | 30 | 41 | 50 | 60 While the key you are search for is 50. Show the stack trace.
Write recursive method to return true if a given array of integers, named numbers, with n...
Write recursive method to return true if a given array of integers, named numbers, with n occupied positions is sorted in ascending (increasing) order, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary. // An empty array and an array with single element in it, are sorted. Method isSortedRec must be recursive and returns...
IN JAVA: Write recursive method to return true if a given array has element equal to...
IN JAVA: Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp,...
Write recursive method to return true if a given array has element equal to employee emp,...
Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp, and returns...
1. Write a C++ program that implements the recursive function isMember as declared above. Pass an...
1. Write a C++ program that implements the recursive function isMember as declared above. Pass an array to the function by reference. Here are two sample runs of the program. The elements of the array are: 0 4 5 6 7 Enter the element you want to find: 6 Element is in the array Press any key to continue . . .
1) a. Write the C++ program that uses a recursive function to print the elements of...
1) a. Write the C++ program that uses a recursive function to print the elements of a list in reverse order. b. Write the pseudocode for the program.
Write a binary recursivealgorithm that finds the maximum into an array. And apply it to the...
Write a binary recursivealgorithm that finds the maximum into an array. And apply it to the following array:  8 |6 | 19 | 2 | 3 |2 |1 Show (1) the stack trace and (2) the recursive tree. You can draw them by hand on paper and attach them a picture your answers in the word document.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT