fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct{
  4. double time;
  5. double voltage;
  6. }
  7. SensorData;
  8.  
  9. int main(){
  10. SensorData data[]={
  11. {0.0, 2.3}, {0.5, 2.3}, {1.0, 2.3},
  12. {1.2, 4.6}, {1.5, 4.6}, {2.0, 4.6}, // 1つ目のピーク
  13. {2.2, 2.3}, {3.0, 2.3}, {3.5, 2.3},
  14. {3.7, 4.6}, {4.0, 4.6}, {4.5, 4.6}, // 2つ目のピーク
  15. {5.0, 4.6}
  16. };
  17.  
  18. int data_count=sizeof(data)/sizeof(data[0]);
  19. double max_voltage=data[0].voltage;
  20. double peak_time=data[0].time;
  21.  
  22. for(int i=1; i<data_count; i++) {
  23. if(data[i].voltage>max_voltage){
  24. max_voltage=data[i].voltage;
  25. peak_time=data[i].time;
  26. }
  27. }
  28.  
  29. printf("ピーク電位: %.2f V\n", max_voltage);
  30. printf("出現時間 : %.3f 秒\n", peak_time);
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
ピーク電位: 4.60 V
出現時間  : 1.200 秒