fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int i,a[30];
  5. a[0] = 2;a[1] = -1;
  6. for(i=2;i<30;i++){
  7. a[i] = -a[i-1]+a[i-2]+2; //数列の計算
  8. if(a[i]>5000){ //5000を超える条件
  9. printf("5000を超えるのは%d項目",i); //結果の表示
  10. break;
  11. }
  12. }
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
5000を超えるのは18項目