fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define R 3000
  5. #define L 0.001
  6. #define E 5
  7. #define MAX_TIME 0.1
  8. #define NUM_POINTS 10
  9.  
  10. int main() {
  11. double current = 0.0;
  12. double time = 0.0;
  13. double tau = L / R;
  14. double dt = MAX_TIME / NUM_POINTS;
  15. double voltage = E;
  16. int i;
  17. printf("Time (s), Current (A)\n");
  18.  
  19. for (i = 0; i <= NUM_POINTS; i++) {
  20. current = (voltage / R) * (1 - exp(-time / tau));
  21.  
  22. printf("%lf, %lf\n", time, current);
  23.  
  24. time += dt;
  25. }
  26.  
  27. printf("計算が終了しました。\n");
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Time (s), Current (A)
0.000000, 0.000000
0.010000, 0.001667
0.020000, 0.001667
0.030000, 0.001667
0.040000, 0.001667
0.050000, 0.001667
0.060000, 0.001667
0.070000, 0.001667
0.080000, 0.001667
0.090000, 0.001667
0.100000, 0.001667
計算が終了しました。