C program that reads parameter float (Vin) and a second parameter float (Vout ) and print the load resistor needed for this design with its unit
Posted by Samath
Last Updated: January 01, 2017

Assume an ideal voltage divider circuit. Write a C program that reads from the console a parameter float (Vin) and a second parameter float (Vout ) and print the load resistor needed for this design with its unit. Fix the other resistor to 1kOhm.

Code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	float Vout;//Declaring float variables output and input voltages
	float Vin;
	float R1 = 1000;//asigning the fixed resistor to 1 Kohm

	printf("\nPlease enter the input voltage\n");
	scanf("%f",&Vin);
	printf("\nEnter the output voltage\n");
	scanf("%f",&Vout);
	float Rload;//declaring variable that is being calculated
	Rload = (-R1*Vout)/(Vout-Vin);
	printf("The Load resistor needed for this design is %f\n",Rload);
	system("PAUSE");
	return 0;
}