Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Last active June 13, 2016 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/14cedd4b6e294b535a7e75bed88b1349 to your computer and use it in GitHub Desktop.
Save CraigRodrigues/14cedd4b6e294b535a7e75bed88b1349 to your computer and use it in GitHub Desktop.
Recursive Counting Function
#include "stdio.h"
//n is the last index of the array
int arr_count(int count, int n)
{
//base case
if (n == 0)
{
return count;
}
return (count + arr_count(count,n-1));
}
int main(void) {
// Disable stdout buffering
setvbuf(stdout, NULL, _IONBF, 0);
int arr[] = {1,2,3,4,5,6,7,8,9};
int count = 1;
count = arr_count(count, 8);
printf("\ncount is: %d\n", count);
return 0;
}
@CraigRodrigues
Copy link
Author

First time using repl.it

@CraigRodrigues
Copy link
Author

No real use of the array though. It just uses the count. Hmmm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment