
Patrick B. answered 04/21/20
Math and computer tutor/teacher
#include <stdio.h>
#define MAX_INDEX (5)
int smallestSum=32767;
void jumpit ( int * A, int iIndexPos,int sum)
{
printf(" jump it : iIndexPos = %d : sum = %d \n",iIndexPos,sum);
if (iIndexPos<MAX_INDEX)
{
//can always jump one position from current index
iIndexPos++;
sum += A[iIndexPos];
jumpit(A,iIndexPos,sum);
// can jump one OR two positions from current index
if ((MAX_INDEX-iIndexPos)>=2)
{
iIndexPos +=2;
sum += A[iIndexPos];
jumpit(A,iIndexPos,sum);
}
}
if (sum < smallestSum)
{
printf(" updating smallestSum to %d \n",sum);
smallestSum = sum;
}
}
int main()
{
int a[6]={0,3,80,6,59,10};
jumpit(a,0,0);
printf(" smallest sum is %d ",smallestSum+a[MAX_INDEX]);
}