How to write a C Program to Convert Celsius to Fahrenheit, Fahrenheit to Celsius and Kelvin to Fahrenheit in C Programming Language ?
This C Program Change given temperature into Celsius to Fahrenheit, Fahrenheit to Celsius and Kelvin to Fahrenheit.
Temperature (F,C,K) is enter by the user through keyboard.
Solution:
- #include <stdio.h>
- int main(int argc, char **argv)
- {
- float temp=0;
- float kelvin=0;
- float celsius=0;
- float fahrenheit=0;
- char unit;
- printf("Enter a temperature number\n");
- scanf("%f", &temp);
- printf("you entered %f, what unit are you using(F,C,K)", temp);
- scanf("%c,", &unit);
- printf("%c.". &unit);
- if(unit=='c'){
- kelvin=temp-273.15;
- fahrenheit=temp*9/5+32;
- printf("%f Celsius =%f Fahrenheit and %f Kelvin", temp, fahrenheit, kelvin);
- }
- else if(unit=='f'){
- celsius=(fahrenheit-32)*5/9;
- kelvin=celsius-273.15;
- printf("%f Fahrenheit =%f Celsius and %f Kelvin", temp, fahrenheit, kelvin);
- }
- else if(unit=='k'){
- celsius=temp+273.15;
- fahrenheit=celsius*9/5+32;
- printf("%f Kelvin =%f fahrenheit and %f celsius", temp,fahrenheit, celsius);
- }
- else{
- printf("\n why did you do this");
- }
- return 0;
- }