Skip to content

Instantly share code, notes, and snippets.

@odiak
Created April 16, 2011 00:58
Show Gist options
  • Save odiak/922732 to your computer and use it in GitHub Desktop.
Save odiak/922732 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int sum (int n, int a, int r) {
if (n == 1) {
return a;
}
return a + r * sum(n - 1, a, r);
}
int main (int argc, char *argv[]) {
printf("%d\n", sum(10, 1, 2));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment