So I am trying to create an algorithm in C that finds the Min number of an array A[n] using recursion.
What the algorithm does is split the array to 2 equal subsections until the subsections become with only one position left. Until n = 1 so min = A[0]. Then it goes back and the subsectopms start comparing each other.
This is where I have gotten so far.
#include <stdio.h>
#define N 10
int min_num(double T[],int n);
int main()
{
double T[]={4,5,10,5,7,3,6,2,8,9};
double min;
min = min_num(T,N);
printf("min = %g\n",min);
return 0;
}
int min_num(double T[],int n)
{
double min; // the min number
if (n == 1)
min = T[0];
else
{
int k;
k = n/2;
double SubsectionA_T[k];
double SubsectionB_T[n-k];
int i;
double x,y;
for (i=0;i<k;i++)
SubsectionA_T[i] = T[i];
for (i=k; i<N; i++)
SubsectionB_T[i] = T[i];
x = min_num(SubsectionA_T, k);
y = min_num(SubsectionB_T, n-k);
min = x;
if (x > y)
min = y;
}
return min;
}