Problem Statement: Write a C program to convert a temperature in Celsius to Fahrenheit
Description:
This program converts a given temperature from Celsius to Fahrenheit using the formula: Fahrenheit = (Celsius * 9/5) + 32
It demonstrates basic input/output functions and arithmetic operations in C.
Usage:
The user inputs a temperature in Celsius, and the program converts and displays the equivalent temperature in Fahrenheit.
Code:
#include <stdio.h>
int main() {
float celsius, fahrenheit;
// Asking user to input temperature in Celsius
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
// Converting to Fahrenheit
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);
return 0;
}
Explanation:
The program is designed to take a temperature input in Celsius from the user and convert it to Fahrenheit using the formula:
Breakdown of the Code:
#include
int main()
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);
return 0;
Sample Input/Output:
Input:
Enter temperature in Celsius: 25
Output:
25.00 Celsius = 77.00 Fahrenheit
Summary:
The program reads a temperature in Celsius, converts it to Fahrenheit using a mathematical formula, and displays the result to the user. It demonstrates basic arithmetic and input/output operations in C programming.
Test here: