#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_R;
printf("\nRC Circuit Resistor Voltage (V_R)\n"); printf("Time (s) Voltage (V)\n"); printf("----------------------\n");
for (t = 0; t <= TIME_MAX; t += TIME_STEP) {
V_R
= V_INITIAL
* exp(-t
/ (R
* C
)); printf("%8.3f %6.3f | ", t
, V_R
);
int barLength = (int)(V_R / V_INITIAL * 50); // Scale for ASCII plot
for (int i = 0; i < barLength; i++) {
}
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgojZGVmaW5lIFZfSU5JVElBTCA1LjAgIC8vIEluaXRpYWwgdm9sdGFnZSBpbiB2b2x0cwojZGVmaW5lIFIgMTAwMDAgICAgICAgIC8vIFJlc2lzdGFuY2UgaW4gb2htcyAoMTBrzqkpCiNkZWZpbmUgQyAwLjAwMDAwMSAgICAgLy8gQ2FwYWNpdGFuY2UgaW4gZmFyYWRzICgxwrVGKQojZGVmaW5lIFRJTUVfTUFYIDAuMDUgIC8vIE1heGltdW0gdGltZSBpbiBzZWNvbmRzCiNkZWZpbmUgVElNRV9TVEVQIDAuMDAyIC8vIFRpbWUgc3RlcCBmb3IgcGxvdHRpbmcKCnZvaWQgcGxvdEdyYXBoKCk7CgppbnQgbWFpbigpIHsKICAgIHBsb3RHcmFwaCgpOwogICAgcmV0dXJuIDA7Cn0KCnZvaWQgcGxvdEdyYXBoKCkgewogICAgZG91YmxlIHQsIFZfUjsKICAgIHByaW50ZigiXG5SQyBDaXJjdWl0IFJlc2lzdG9yIFZvbHRhZ2UgKFZfUilcbiIpOwogICAgcHJpbnRmKCJUaW1lIChzKSAgIFZvbHRhZ2UgKFYpXG4iKTsKICA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MgQ2lyY3VpdCBEaXNjaGFyZ2luZyBDdXJyZW50IChJKVxuJnF1b3Q7KTsKICAgIHByaW50ZigmcXVvdDtUaW1lIChzKSAgIEN1cnJlbnQgKEEpXG4mcXVvdDspOwogICAgcHJpbnRmKCZxdW90Oy0tLS0tLS0tLS0tLS0tLS0tLS0tLS1cbiZxdW90Oyk7CiAgICAKICAgIGZvciAodCA9IDA7IHQgJmx0Oz0gVElNRV9NQVg7IHQgKz0gVElNRV9TVEVQKSB7CiAgICAgICAgSSA9IChWX0lOSVRJQUwgLyBSKSAqIGV4cCgtdCAvIChSICogQykpOwogICAgICAgIHByaW50ZigmcXVvdDslOC4zZiAgICU2LjZmIHwgJnF1b3Q7LCB0LCBJKTsKICAgICAgICAKICAgICAgICBpbnQgYmFyTGVuZ3RoID0gKGludCkoSSAvIChWX0lOSVRJQUwgLyBSKSAqIDUwKTsgLy8gU2NhbGUgZm9yIEFTQ0lJIHBsb3QKICAgICAgICBmb3IgKGludCBpID0gMDsgaSAmbHQ7IGJhckxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgIHByaW50ZigmcXVvdDsjJnF1b3Q7KTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCZxdW90O1xuJnF1b3Q7KTsKICAgIH0KfQo=
#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, I;
printf("\nRC Circuit Discharging Current (I)\n");
printf("Time (s) Current (A)\n");
printf("----------------------\n");
for (t = 0; t <= TIME_MAX; t += TIME_STEP) {
I = (V_INITIAL / R) * exp(-t / (R * C));
printf("%8.3f %6.6f | ", t, I);
int barLength = (int)(I / (V_INITIAL / R) * 50); // Scale for ASCII plot
for (int i = 0; i < barLength; i++) {
printf("#");
}
printf("\n");
}
}