C Program to Convert Celsius to Fahrenheit
This program demonstrates how to convert a temperature from Celsius to Fahrenheit using C programming.
Concept Overview
Celsius and Fahrenheit are two common temperature scales. The conversion formula is: F = (C × 9/5) + 32 This program takes user input in Celsius and calculates the corresponding Fahrenheit value.
Program
C
#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
// Conversion formula
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);
return 0;
}
Output
Enter temperature in Celsius: 37 37.00 Celsius = 98.60 Fahrenheit
Explanation
- `float celsius, fahrenheit;` – Variables to store temperature values.
- `scanf()` – Reads user input in Celsius.
- `fahrenheit = (celsius * 9 / 5) + 32;` – Converts Celsius to Fahrenheit.
- `printf()` – Displays the converted Fahrenheit temperature with two decimal precision.
Note: ⚠️ Note: Using floating-point variables allows handling decimal precision in temperature conversion.
Codecrown