Write a C program that calculates the voltage of the circuit below.

Exercise 1.5 Circuit

Take R1 = 2Ω, R2 = 4Ω, R3 = 10Ω, I = 20A

Source Code

Brief explanation is provided after the source code.

#include <stdio.h>

int main(void)
{
	int r1 = 2, r2 = 4, r3 = 10, I = 20;
	float V, Rp;
	Rp = (float)(r1 * r2 * r3)/(r2*r3 + r1*r3 + r1*r2);
  	V = I * Rp;
	printf("Voltage: %.2f\n", V);

	return 0;
}

When you compile and execute the above program it produces the following result on Linux:

Voltage: 23.53

Brief Explanation

  • The program first compute the total resistance of the parallel resistors.
  • Using the formula V = IRp , the voltage is computed.
  • Using printf function, the voltage is printed to the stdout.

Add comment


Security code
Refresh