fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. double t[] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0};
  5. double v[] = {2.85, 2.85, 2.85, 2.85, 2.85, 2.85, 2.85, 2.85, 2.85, 2.85, 2.86, 2.85, 2.85, 2.85, 2.85, 2.86, 2.85, 2.86, 2.85, 2.85, 2.86, 2.85, 2.86, 2.86, 2.86, 2.85, 2.85, 2.85, 2.86, 2.85, 2.86, 2.85, 2.85, 2.85, 2.84, 2.86, 2.85, 2.85, 2.85, 2.86, 2.85};
  6.  
  7. // データ数を自動計算(これで「int n = 41」と書かなくて済む)
  8. int n = sizeof(v) / sizeof(v[0]);
  9. int count = 1;
  10.  
  11. printf("【解析結果】\n");
  12.  
  13. for (int i = 1; i < n - 1; i++) {
  14. // ピーク判定(前より大きく、後ろ以上、かつ2.86以上)
  15. if (v[i] > v[i-1] && v[i] >= v[i+1] && v[i] >= 2.86) {
  16. printf("%d回目:%.1fs, %.2fV\n", count++, t[i], v[i]);
  17. }
  18. }
  19. return 0;
  20. }
  21.  
  22.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
【解析結果】
1回目:1.0s, 2.86V
2回目:1.5s, 2.86V
3回目:1.7s, 2.86V
4回目:2.0s, 2.86V
5回目:2.2s, 2.86V
6回目:2.8s, 2.86V
7回目:3.0s, 2.86V
8回目:3.5s, 2.86V
9回目:3.9s, 2.86V