#include <stdio.h>
#include <math.h>
int main() {
// パラメータの定義
double R = 3000.0; // 抵抗 (オーム)
double L = 0.001; // インダクタンス (ヘンリー)
double V_E = 5.0; // 電源電圧 (ボルト)
int steps = 100; // 計算ステップ数
double t_max = 0.001; // 計算する最大時間 (秒)
int i; // ループ変数を外で宣言
// 時定数 τ = L / R
tau = L / R;
// 時間変化に伴う電流 I(t) を計算
printf("Time(s)\tCurrent(A)\n"); for (i = 0; i <= steps; i++) { // ループの外で宣言した i を使用
time = t_max
* i
/ steps
; I
= (V_E
/ R
) * (1 - exp(-time / tau
)); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgbWFpbigpIHsKICAgIC8vIOODkeODqeODoeODvOOCv+OBruWumue+qQogICAgZG91YmxlIFIgPSAzMDAwLjA7ICAvLyDmirXmipcgKOOCquODvOODoCkKICAgIGRvdWJsZSBMID0gMC4wMDE7ICAgLy8g44Kk44Oz44OA44Kv44K/44Oz44K5ICjjg5jjg7Pjg6rjg7wpCiAgICBkb3VibGUgVl9FID0gNS4wOyAgIC8vIOmbu+a6kOmbu+WcpyAo44Oc44Or44OIKQogICAgZG91YmxlIHRpbWUsIEksIHRhdTsKICAgIGludCBzdGVwcyA9IDEwMDsgICAgLy8g6KiI566X44K544OG44OD44OX5pWwCiAgICBkb3VibGUgdF9tYXggPSAwLjAwMTsgLy8g6KiI566X44GZ44KL5pyA5aSn5pmC6ZaTICjnp5IpCiAgICBpbnQgaTsgIC8vIOODq+ODvOODl+WkieaVsOOCkuWkluOBp+Wuo+iogAoKICAgIC8vIOaZguWumuaVsCDPhCA9IEwgLyBSCiAgICB0YXUgPSBMIC8gUjsKCiAgICAvLyDmmYLplpPlpInljJbjgavkvLTjgYbpm7vmtYEgSSh0KSDjgpLoqIjnrpcKICAgIHByaW50ZigiVGltZShzKVx0Q3VycmVudChBKVxuIik7CiAgICBmb3IgKGkgPSAwOyBpIDw9IHN0ZXBzOyBpKyspIHsgIC8vIOODq+ODvOODl+OBruWkluOBp+Wuo+iogOOBl+OBnyBpIOOCkuS9v+eUqAogICAgICAgIHRpbWUgPSB0X21heCAqIGkgLyBzdGVwczsKICAgICAgICBJID0gKFZfRSAvIFIpICogKDEgLSBleHAoLXRpbWUgLyB0YXUpKTsKICAgICAgICBwcmludGYoIiVmXHQlZlxuIiwgdGltZSwgSSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K