Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program with the following functions: double minValue( const double a[

ID: 3819205 • Letter: W

Question

Write a C program with the following functions:

double minValue( const double a[], unsigned els);

double minIndex(const double a[], unsigned els);

Please use exactly these prototypes.

For both functions, els is the number of elements in array a, and your function may assume withoutchecking that els > 0.

The usual rule for recursion exercises: neither of these functions, nor their helper functions, may usewhile, for, do-while, or goto statements. You're supposed to make the repetition happen withrecursion, not explicit looping. (It's fine if you want to have standing loops in your main to test yourfunctions.) As always, it's fine to write helper functions.

For example, if main had an array of doubles named blah holding {1.0, -2.0, 3.0, -4.0, 5.0, -4.0, -4.0},then minValue(blah, 7) should return -4.0, because that's the smallest value in the array.minIndex(blah, 7) should return 3. The smallest value in this array appears in blah[3], blah[5], andblah[6]; the smallest such index, 3 in this case, is returned.

Neither minValue's job nor minIndex's job includes doing any I/O.

Your main should call minValue and minIndex. You decide the details of your main.

Explanation / Answer

#include <stdio.h>
//methods declarations
double minValue(const double a[],unsigned els);
double minIndex(const double a[],unsigned els);
//static variables used in my recursion
static int index1=1;
static int index2=1;
static double minVal;
static double minInd=0;

int main()
{
  
   unsigned els=5;
   double a[] = {6,0.3,4.5,-0.8,-3};
  
   printf("Min Value : %f ",minValue(a,els));
   printf("Min Index : %d",(int)minIndex(a,els));
  
   return 0;
}
//This function will return minimum value present in double array 'a' by using recursion concept
double minValue(const double a[],unsigned els)
{
   //assuming first value of array as minimum value
   if(index1==1)
   minVal = a[0];
   if(els>index1)//base case for recursion. loop till we reach index that is equal to els,i.e size of array 'a'
   {
       if(a[index1]<minVal)
       minVal = a[index1];//storing minimum value
       index1++;//incrementing index to access next value of array
       minValue(a,els);//recursion
   }
   return minVal;
}
//This function will return index of minimum value present in double array 'a' by using recursion concept
double minIndex(const double a[],unsigned els)
{
   //assuming first value of array as minimum value
   if(index2==1)
   minVal = a[0];
   if(els>index2)//base case for recursion. loop till we reach index that is equal to els,i.e size of array 'a'
   {
       if(a[index2]<minVal)
       {
           minVal = a[index2];//storing minimum value
           minInd = index2;//storing minimum index
       }
       index2++;//incrementing index to access next value of array
       minIndex(a,els);//recursion
   }
   return minInd;
}

Sample Input:

    unsigned els=5;
   double a[] = {6,0.3,4.5,-0.8,-3};

Sample Output:

    Min Value : -3.000000
    Min Index : 4

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote