fork download
  1. #include <stdio.h>
  2. int func(int n){
  3. int i,a[30];
  4. a[1]=1;
  5. a[2]=2;
  6. for(i=3;i<=n;i++){
  7. a[i]=-2*a[i-1]+2*a[n-2];
  8. }
  9. return a[n];
  10. }
  11. int main(void) {
  12. // your code goes here
  13. int n=3;
  14. printf("数列anについて、n=%dの時%d",n,func(n));
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0.01s 5260KB
stdin
Standard input is empty
stdout
数列anについて、n=3の時-2