Ohm\'s Law models the current through a conductor as follows: I =V/R where V is
ID: 3648532 • Letter: O
Question
Ohm's Law models the current through a conductor as follows:I =V/R
where V is the voltage (in volts), R is the resistence (in Ohms) and I is the current (in amps). Write a
program that, given two of these values computes the third using Ohm's Law.
The program should work as follows: it prompts the user for units of the rst value: the user should be
prompted to enter V, R, or I and should then be prompted for the value. It should then prompt for the
second unit (same options) and then the value. The program will then output the third value depending
on the input. An example run of the program:
Explanation / Answer
#include int main() { char a[2]; double p,q,r; printf("Enter V or I or R "); scanf("%c",&a[0]); printf("Enter Value "); scanf("%f",&p); printf("Enter V or I or R EXCEPT FIRST ENTERED ONE "); scanf("%c",&a[1]); printf("Enter Value "); scanf("%f",&q); r=p/q; if(((a[0]=='I') ||(a[0]=='V'))&&((a[1]=='V')||(a[1]=='I'))) { printf("Resistance = %f ohms",r); } else if(((a[0]=='I')||(a[0]=='R'))&&((a[1]=='I')||(a[1]=='R'))) { printf("voltage = %f volts",r); } else if(((a[0]=='V') || (a[0]=='R'))&&((a[1]=='V')||(a[1]=='R'))) { printf("current = %f amps",r); } return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.