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
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 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,...
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 . . .
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
Write a C++ recursive function that counts the number of nodes in a singly linked list....
Write a C++ recursive function that counts the number of nodes in a singly linked list. (a) Test your function using different singly linked lists. Include your code. (b) Write a recurrence relation that represents your algorithm. (c) Solve the recurrence relation using the iterating or recursive tree method to obtain the running time of the algorithm in Big-O notation.
Write a C++ program to perform the following tasks     a) Declare an integer array of...
Write a C++ program to perform the following tasks     a) Declare an integer array of size 1000.     b) Initialize the array with random values between 1 and 9.     c) Write the code to find and print, how many 1’s occur in the array.
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
In C Not C++ write a function that takes in the reference of an int array...
In C Not C++ write a function that takes in the reference of an int array and return the value -1 if sum is odd, and 1 if the sum is even.