Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

solve this question and show answer step by step do it on matlab 1. (5 pts) Writ

ID: 3184492 • Letter: S

Question


solve this question and show answer step by step do it on matlab

1. (5 pts) Write a script that will prompt the user for a temperature in degrees Celsscecified by th and , then an F for Fahrenheit or K for Kelvin. The script will print the corresponding tempera user. For example, the output might look like this: in the scale specified by the Enter the temp in degrees C: 27.3 Do you want F or K? K The temp in degrees F is 300.4 K. The The format of the output should be exactly as specified here. Assume the user enters only For conversions are: F-+32 K C+273.15

Explanation / Answer

Steps:

Store f value as 1 and  k value as 2;

Ask to enter f or k then store this inpu in x (here f for Fahrenheit and k for Kelvin)

Using switch x

if x=f that is x=1 then Ask to enter Celsius value

Fahrenheit=Celsius*9/5+32

if x=k that is x=2 then Ask to enter Celsius value

Kelvin=Celsius+273.15

MATLAB CODE

clc
clear all

f=1;
k=2;
disp('Celsius to Fahrenheit or Kelvin');
x = input('Type f for Farenheit and Type k for Kelvin: ');
switch x
case 1
Celsius=input('Enter a temperature in Celsius: ');
disp([ num2str(Celsius*9/5+32) ' Fahrenheit']);
case 2
Celsius=input('Enter a temperature in Celsius: ');
disp([ num2str(Celsius+273.15) ' Kelvin ' ]);
end