C program for temperature conversion in different scale.

#include<stdio.h>
#include<conio.h>
void main(){
float ct,kt,ft,rt;
char choice;
clrscr();
printf("Temperature Conversion Program\nInput Temprature in one of the Following scale-\nc/k/f/r\n Enter Your Choice\n");
scanf("%c",&choice);
switch (choice){
case 'c': case 'C': 
printf("Enter Temperature in Celsius\n");
scanf("%f",&ct);
kt=273+ct;
ft=((9/5.0)*ct)+32;
rt=((4/5.0)*ct);
break;
case 'k': case 'K': 
printf("Enter Temperature in Kelvin\n");
scanf("%f",&kt);
ct=kt-273;
ft=((9/5.0)*(kt-273))+32;
rt=((4/5.0)*(kt-273));
break;
case 'f': case 'F': 
printf("Enter Temperature in Fahrenheit\n");
scanf("%f",&ft);
ct=((5/9.0)*(ft-32));
kt=((5/9.0)*(ft-32))+273;
rt=((4/9.0)*(ft-32));
break;
case 'r': case 'R': 
printf("Enter Temperature in Rumor\n");
scanf("%f",&rt);
ct=(5/4.0)*rt;
kt=((5/4.0)*rt)+273;
ft=((9/4.0)*rt);
break;
default: printf("Wrong Input\n");
}
printf("Temperature in Different Scale:-\n Celcius=%f\n Kelvin=%f\n Fahrenheit=%f\n Rumor=%f\n",ct,kt,ft,rt);
getch();
}

No comments:

Post a Comment