Celsius to Fahrenheit Conversion Guide

Sep 9, 2024

Tutorial 15: Temperature Conversion Program

Overview

  • Objective: Write a program to convert temperature from Celsius to Fahrenheit.
  • Program Name: temperature_conversion.c
  • Complexity: Simple, fun exercise focusing on basic input-output and calculations in C.

Program Structure

  • File Name: temperature_conversion.c

Code Breakdown

  1. Comments:

    • Line 1-2: // Input temperature in degree Celsius and convert to degree Fahrenheit
  2. Header File:

    • Line 3: Include standard header files needed for input-output operations.
  3. Main Function:

    • Line 4: Declare main() function.
    • Add curly braces for function scope.
  4. Variable Declaration:

    • Declare a variable temp of type float to store the temperature in Celsius.

Input and Output

  • Input:

    • Use printf to prompt the user to input temperature in Celsius.
    • Use scanf to read the input value.
    • Use %f format specifier for floating-point numbers.
    • Store result in temp using address-of operator &temp.
  • Output:

    • Display equivalent temperature in Fahrenheit.
    • Use printf with a message and %f to show the computed value.

Conversion Formula

  • Formula:
    • Multiply the Celsius temperature by 1.8 and add 32 to convert to Fahrenheit.
    • No parentheses needed due to operator precedence (multiplication before addition).

Example Execution

  • Example: Input 37 Celsius should output 98.6 Fahrenheit.
  • Note: 37 Celsius is normal body temperature.

Conclusion

  • Summary: A very simple program with only 4 lines of executable code.
  • Next Steps: Stay tuned for more interesting topics in upcoming tutorials.

Additional Info

  • Channel Info: Thank viewers and encourage subscription.
  • Personal Note: Presenter shares personal achievement in remembering conversion values from school.