- #include <stdio.h>
- int main() {
- // Resistors values in ohms
- int resistors[3] = {2000, 5000, 8000}; // R1 = 2k ohm, R2 = 5k ohm, R3 = 8k ohm
- // Total resistance
- int total_resistance = 0;
- // Calculate total resistance by summing up all the resistor values
- for (int i = 0; i < sizeof(resistors) / sizeof(resistors[0]); i++) {
- total_resistance += resistors[i];
- }
- // Print total resistance
- printf("Total resistance in the circuit: %d ohms\n", total_resistance);
- // Power supply voltage
- int power_supply_voltage = 9; // 9 volts
- // Calculate current using Ohm's Law (I = V/R)
- float current = (float) power_supply_voltage / total_resistance;
- // Print current
- printf("Current flowing through the circuit: %.2f mA\n", current * 1000); // Convert current to mA
- return 0;
- }
[text] coding
Viewer
Editor
You can edit this paste and save as new: