Write a Matlab function convert T such that convert T(x, ’C’) converts from degrees Celsius to degrees Fahrenheit, while convert T(x, ’F’) converts from Fahrenheit to Celsius.
Need to submit program online to see if successful. Please help!
function T = convert_T (x, flag)
%convert between Celsius and Fahrenheit temperatures
%for example, convert_T(10, 'C') should return 50
%and convert_T(50, 'F') should return 10
Input Code:
function T = convert_T(x,flag)
if (flag == 'F' || flag == 'f')
converted = (x-32)*(5/9);
convertedto = 'C';
T =converted;
elseif (flag == 'C' || flag == 'c')
converted = x*(9/5) + 32;
convertedto = 'F';
T =converted;
else
fprintf('\nYou have given a wrong input\n')
end
==================================================
Note:you go to the command prompt and type “convert_T(inputvalue1, inputvalue2)”. This means you type your function's name and the values you want to assign to the inputs.Then you will get result
Get Answers For Free
Most questions answered within 1 hours.