0% found this document useful (0 votes)
6 views3 pages

PC Project cp3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

PC Project cp3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

program that converts temperature between Celsius, Fahrenheit, and Kelvin in c program

#include <stdio.h>

// Function to convert Celsius to Fahrenheit


float celsiusToFahrenheit(float celsius) {
return (celsius * 9/5) + 32;
}

// Function to convert Celsius to Kelvin


float celsiusToKelvin(float celsius) {
return celsius + 273.15;
}

// Function to convert Fahrenheit to Celsius


float fahrenheitToCelsius(float fahrenheit) {
return (fahrenheit - 32) * 5/9;
}

// Function to convert Fahrenheit to Kelvin


float fahrenheitToKelvin(float fahrenheit) {
return (fahrenheit - 32) * 5/9 + 273.15;
}

// Function to convert Kelvin to Celsius


float kelvinToCelsius(float kelvin) {
return kelvin - 273.15;
}

// Function to convert Kelvin to Fahrenheit


float kelvinToFahrenheit(float kelvin) {
return (kelvin - 273.15) * 9/5 + 32;
}

int main() {
int choice;
float temperature;

printf("Temperature Converter\n");
printf("Select the conversion type:\n");
printf("1. Celsius to Fahrenheit\n");
printf("2. Celsius to Kelvin\n");
printf("3. Fahrenheit to Celsius\n");
printf("4. Fahrenheit to Kelvin\n");
printf("5. Kelvin to Celsius\n");
printf("6. Kelvin to Fahrenheit\n");
printf("Enter your choice (1-6): ");
scanf("%d", &choice);

printf("Enter temperature: ");


scanf("%f", &temperature);
switch (choice) {
case 1:
printf("%.2f Celsius = %.2f Fahrenheit\n", temperature, celsiusToFahrenheit(temperature));
break;
case 2:
printf("%.2f Celsius = %.2f Kelvin\n", temperature, celsiusToKelvin(temperature));
break;
case 3:
printf("%.2f Fahrenheit = %.2f Celsius\n", temperature, fahrenheitToCelsius(temperature));
break;
case 4:
printf("%.2f Fahrenheit = %.2f Kelvin\n", temperature, fahrenheitToKelvin(temperature));
break;
case 5:
printf("%.2f Kelvin = %.2f Celsius\n", temperature, kelvinToCelsius(temperature));
break;
case 6:
printf("%.2f Kelvin = %.2f Fahrenheit\n", temperature, kelvinToFahrenheit(temperature));
break;
default:
printf("Invalid choice\n");
}

return 0;
}

Explanation:
1. Functions: The program contains functions to convert between the different temperature
units:
• celsiusToFahrenheit(float celsius)
• celsiusToKelvin(float celsius)
• fahrenheitToCelsius(float fahrenheit)
• fahrenheitToKelvin(float fahrenheit)
• kelvinToCelsius(float kelvin)
• kelvinToFahrenheit(float kelvin)
Main Function:
• The user is asked to choose the type of conversion they wish to perform (1-6).
• The program reads the temperature value and performs the selected conversion.
• It then outputs the result in the corresponding unit.
Output

You might also like