Skip to content

Instantly share code, notes, and snippets.

@cohalz
Created October 1, 2013 04:41
Show Gist options
  • Save cohalz/6773943 to your computer and use it in GitHub Desktop.
Save cohalz/6773943 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int recursion(int n){
if(n == 1) return 1;
if(n == 2) return 2;
return 3*recursion(n-1)+2*recursion(n-2);
}
int main(){
int n,i;
printf("n = ");
while(scanf("%d", &n) != 1 || n < 3) {
printf("#n must be at least 3.\n");
while(getchar() != '\n') {};
printf("n = ");
}
for(i=1;i<=n;i++){
printf("%d ",recursion(i));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment