代码文本:
#include "stdio.h"
int myf(int n){
if(n==1 || n==2)
return 1;
return 3*myf(n-1)+2*myf(n-2);
}
int main(int argc,char *argv[]){
int sum,n,t;
printf("Enter n(int n>0)...\nn=");
if(scanf("%d",&n) && n>0){
for(sum=0,t=1;t t=myf(n); printf("%d\t%d\n",t,t+sum); } else printf("Input error, exit...\n"); return 0; }
#include
int f(int n, int f1, int f2) {
if (n == 1)
return f1;
else
return f(n - 1, f2, 3 * f2 + 2 * f1);
}
int main() {
int n, s = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
s += f(i,1,1);
printf("%d %d", f(n, 1, 1), s);
return 0;
}