Temperature Converter

Easy
1
14.7% Acceptance

In this lab, you will create a program in C that converts temperature between Celsius and Fahrenheit. The program should be able to take a temperature value along with a unit (c for Celsius or f for Fahrenheit) as input and convert it to the other unit.

To convert from Celsius to Fahrenheit, you can use the formula: F = (C * 9/5) + 32

To convert from Fahrenheit to Celsius, you can use the formula: C = (F - 32) * 5/9

Examples

Example 1:

c 98.6 37.0

In this example, the user inputs c to indicate that the output temperature is in Celsius, followed by the temperature value 98.6 (fahrenheit). The program converts 98.6°F to Fahrenheit and outputs 37.0.

Example 2:

f 37.0 98.6

In this example, the user inputs f to indicate that the outout temperature required is in Fahrenheit, followed by the temperature value 37.0. The program converts 37.0°C to Fahrenheit and outputs 98.6.

Make sure to display only the first decimal input. If the value is 34.123 display only 34.1

Remember to use appropriate data types for storing the temperature values and perform the necessary arithmetic operations for the conversion. Good luck with your lab!