Celsius to Fahrenheit or vice versa

442 views (last 30 days)
Riri
Riri on 20 Jan 2014
Answered: Dheeraj Maurya on 30 Jun 2022
Creating a program to convert Celsius to Fahrenheit

Accepted Answer

Amit
Amit on 21 Jan 2014
disp('This program convert Celsius to Fahrenheit');
Celsius=input('Write a temperature in Celsius and you''ll have the result in Fahrenheit: ');
disp([ 'x = ' num2str(Celsius) ' Celcius and y = ' num2str(Celsius*1.8+32) ' Fahrenheit'])
  1 Comment
Amit
Amit on 21 Jan 2014
For both cases:
disp('This program convert Celsius to Fahrenheit');
val = input('Type 1 for Celcius to Farenheit and Type 2 for vice versa: ');
switch val
case 1
Celsius=input('Write a temperature in Celsius and you''ll have the result in Fahrenheit: ');
disp([ 'x = ' num2str(Celsius) ' Celcius and y = ' num2str(Celsius*1.8+32) ' Fahrenheit']);
case 2
Faren=input('Write a temperature in Farenheit and you''ll have the result in Celcius: ');
disp([ 'x = ' num2str(Faren) ' Fahrenheit and y = ' num2str((Faren-32)/1.8) ' Celcius ' ]);
end

Sign in to comment.

More Answers (2)

CJ Grucza
CJ Grucza on 9 Jan 2020
I am able to convert fahrenheit to celsius but i am having a problem with converting celsius to fahrenheit. Why?
  1 Comment
Walter Roberson
Walter Roberson on 9 Jan 2020
We don't know given that little information.
T*9/5+32

Sign in to comment.


Dheeraj Maurya
Dheeraj Maurya on 30 Jun 2022
disp('This program convert Celsius to Fahrenheit');
val = input('Type 1 for Celcius to Farenheit and Type 2 for vice versa: ');
switch val
case 1
Celsius=input('Write a temperature in Celsius and you''ll have the result in Fahrenheit: ');
disp([ 'x = ' num2str(Celsius) ' Celcius and y = ' num2str(Celsius*1.8+32) ' Fahrenheit']);
case 2
Faren=input('Write a temperature in Farenheit and you''ll have the result in Celcius: ');
disp([ 'x = ' num2str(Faren) ' Fahrenheit and y = ' num2str((Faren-32)/1.8) ' Celcius ' ]);

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!