[text] coding

Viewer

  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     // Resistors values in ohms
  5.     int resistors[3] = {2000, 5000, 8000}; // R1 = 2k ohm, R2 = 5k ohm, R3 = 8k ohm
  6.     
  7.     // Total resistance
  8.     int total_resistance = 0;
  9.     
  10.     // Calculate total resistance by summing up all the resistor values
  11.     for (int i = 0; i < sizeof(resistors) / sizeof(resistors[0]); i++) {
  12.         total_resistance += resistors[i];
  13.     }
  14.     
  15.     // Print total resistance
  16.     printf("Total resistance in the circuit: %d ohms\n", total_resistance);
  17.     
  18.     // Power supply voltage
  19.     int power_supply_voltage = 9; // 9 volts
  20.     
  21.     // Calculate current using Ohm's Law (I = V/R)
  22.     float current = (float) power_supply_voltage / total_resistance;
  23.     
  24.     // Print current
  25.     printf("Current flowing through the circuit: %.2f mA\n", current * 1000); // Convert current to mA
  26.     
  27.     return 0;
  28. }
  29.  

Editor

You can edit this paste and save as new:


File Description
  • coding
  • Paste Code
  • 24 Apr-2024
  • 898 Bytes
You can Share it: