fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int a[100];
  5. a[0] = 2;
  6. a[1] = -1;
  7.  
  8. for (int i = 0; i < 98; i++) { // a[i+2] まで使うので i<98
  9. a[i + 2] = -a[i + 1] + a[i] + 2;
  10. if (a[i + 2] > 5000) {
  11. printf("第%d項の値は%dです\n", i + 2, a[i + 2]);
  12. break;
  13. }
  14. }
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
第18項の値は7754です