#include <stdio.h>
#include <math.h>
#define V_INITIAL 5.0 // Initial voltage in volts
#define R 10000 // Resistance in ohms (10kΩ)
#define C 0.000001 // Capacitance in farads (1µF)
#define TIME_MAX 0.05 // Maximum time in seconds
#define TIME_STEP 0.002 // Time step for plotting
void plotGraph();
int main() {
plotGraph();
return 0;
}
void plotGraph() {
double t, V;
printf("\nRC Circuit Discharging Voltage\n"); printf("Time (s) Voltage (V)\n"); printf("----------------------\n");
for (t = 0; t <= TIME_MAX; t += TIME_STEP) {
V
= V_INITIAL
* exp(-t
/ (R
* C
)); printf("%8.3f %6.3f | ", t
, V
);
int barLength = (int)(V / V_INITIAL * 50); // Scale for ASCII plot
for (int i = 0; i < barLength; i++) {
}
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgojZGVmaW5lIFZfSU5JVElBTCA1LjAgIC8vIEluaXRpYWwgdm9sdGFnZSBpbiB2b2x0cwojZGVmaW5lIFIgMTAwMDAgICAgICAgIC8vIFJlc2lzdGFuY2UgaW4gb2htcyAoMTBrzqkpCiNkZWZpbmUgQyAwLjAwMDAwMSAgICAgLy8gQ2FwYWNpdGFuY2UgaW4gZmFyYWRzICgxwrVGKQojZGVmaW5lIFRJTUVfTUFYIDAuMDUgIC8vIE1heGltdW0gdGltZSBpbiBzZWNvbmRzCiNkZWZpbmUgVElNRV9TVEVQIDAuMDAyIC8vIFRpbWUgc3RlcCBmb3IgcGxvdHRpbmcKCnZvaWQgcGxvdEdyYXBoKCk7CgppbnQgbWFpbigpIHsKICAgIHBsb3RHcmFwaCgpOwogICAgcmV0dXJuIDA7Cn0KCnZvaWQgcGxvdEdyYXBoKCkgewogICAgZG91YmxlIHQsIFY7CiAgICBwcmludGYoIlxuUkMgQ2lyY3VpdCBEaXNjaGFyZ2luZyBWb2x0YWdlXG4iKTsKICAgIHByaW50ZigiVGltZSAocykgICBWb2x0YWdlIChWKVxuIik7CiAgICBwcmludGYoIi0tLS0tLS0tLS0t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