The resistance R in ohms of a conductor is given by R = E/I when E is the potential in volts and I is the current in amperes . Write a script that will:
0. call a function to prompt the user for the potential and the current
0. call a function that will print resistance ; this will call a subfunction to calculate and return the resistance .
write the function as well
using MATLAB
function prompt
E = input("Enter Potential in Volts: ");
I = input("Enter Current in Ampere: ");
R = cal(E,I);
function R = cal(E,I)
R = E/I;
end
fprintf("Resistacne is %f ohms",R)
end
Please refer to the screenshot of the code to understand the indentation of the code
Sample Run:
Hope this helped. Please do upvote and if there are any queries please ask in comments section.
Get Answers For Free
Most questions answered within 1 hours.