C Program to Convert Celsius to Fahrenheit

Written: August 15, 2026

Temperature conversion is a friendly first formula program: read a float, apply F = C 9/5 + 32, print the result.

This walkthrough keeps the logic small and readable so you can type it, run it, and then change one input at a time to see what happens.

What you will build

Use floating-point division so 9/5 does not truncate to 1 in integer math.

  • Read Celsius as float
  • Compute f = c 9.0f / 5.0f + 32
  • Print Fahrenheit

Working C example

include <stdio.h>

int main(void) {
    float c, f;
    printf("Celsius: ");
    if (scanf("%f", &c) != 1) return 1;
    f = c  9.0f / 5.0f + 32.0f;
    printf("Fahrenheit = %.2f\n", f);
    return 0;
}

Advertisement

How the logic works

Read the program top to bottom: includes and main first, then the statements that change variables, then the print that proves the result.

If your output looks wrong, print the variables before and after the critical lines. That single habit catches most beginner bugs faster than rewriting the whole file.

Write 9.0/5.0 (or 9.0f/5.0f). Plain 9/5 in integer context becomes 1 and silently breaks the formula.

Advertisement

Keep learning

If this walkthrough on C Program to Convert Celsius to Fahrenheit helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.

Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.

Advertisement

Previous Article

Introduction to Pointers in C: Call by Value vs Call by Reference

Next Article

C Program to Reverse a Number

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨