#include <stdio.h>
//練習問題G
int func(int n){
int a, b=2, c=1;
int i;
if(n==1){
return 1;
}
else if(n==2){
return 2;
}
else{
for(i=2;i<n;i++){
a = -2*b +2*c;
c = b;
b = a;
}
}
return a;
}
int main(void) {
int n = 3;
printf("数列anについて, n=%dのときの値は%d\n", n
, func
(n
)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8v57e057+S5ZWP6aGMRwoKaW50IGZ1bmMoaW50IG4pewogICAgaW50IGEsIGI9MiwgYz0xOwogICAgaW50IGk7CglpZihuPT0xKXsKCQlyZXR1cm4gMTsKCX0KCWVsc2UgaWYobj09Mil7CgkJcmV0dXJuIDI7Cgl9CgllbHNlewoJCWZvcihpPTI7aTxuO2krKyl7CgkJCWEgPSAtMipiICsyKmM7CgkJCWMgPSBiOwoJCQliID0gYTsKCQl9Cgl9CglyZXR1cm4gYTsKfQppbnQgbWFpbih2b2lkKSB7CglpbnQgbiA9IDM7CiAgICBwcmludGYoIuaVsOWIl2Fu44Gr44Gk44GE44GmLCBuPSVk44Gu44Go44GN44Gu5YCk44GvJWRcbiIsIG4sIGZ1bmMobikpOwoJcmV0dXJuIDA7Cn0K