Skip to content

Instantly share code, notes, and snippets.

@AndrewRademacher
Created October 24, 2015 16:18
Show Gist options
  • Save AndrewRademacher/e70f78d038d64ae626b3 to your computer and use it in GitHub Desktop.
Save AndrewRademacher/e70f78d038d64ae626b3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
using namespace std;
int sumArray(int inputArray[], int arrayCount) {
if (arrayCount == 1) {
return inputArray[0];
}
else {
inputArray[0] = inputArray[0] + inputArray[arrayCount - 1];
int newCount = (arrayCount - 1);
return sumArray(inputArray, newCount);
}
}
int main(int argc, char **argv) {
int ary[3];
ary[0] = 4;
ary[1] = 5;
ary[2] = 7;
int sum = sumArray(ary, 3);
printf("%i\n", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment