English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

從鍵盤輸入兩個資料, 第一個為double型態變數degree,第二個為字元C或F或K,
若輸入字元為C, 則要印出F, K度數.
若輸入字元為F, 則要印出C, K度數.
若輸入字元為K, 則要印出C, F度數.
如果輸入的溫度小於絕對溫度0度, 則要印出 "輸入的溫度小於絕對0度."
如果輸入的格式錯誤, 印出 "請以數字加上CFK的格式輸入."

2007-10-13 12:28:21 · 2 個解答 · 發問者 ㄚ健 1 in 電腦與網際網路 程式設計

2 個解答

main(){

double degree;
char a;

while(1){
printf("請輸入數字:");
scanf("%g",°ree);
pirntf("請輸入C,F,K:");
scanf("%c",&a);
if(a=='C'){
printf("F=%g,K=%g",(degree*9)/5+32,degree+273.15)
break;
}
else if(a=='F')
printf("C=%g,K=%g",(degree-32)*5/9,(degree-32)*5/9+273.15)
break;
}
else if(a=='K')
printf("C=%g,F=%g",degree-273.15,(degree-273.15)*9/5+32)
break;
}
else{
printf("請以數字加上C,F,K的格式輸入\n");
printf("請輸入數字:");
scanf("%g",°ree);
pirntf("請輸入C,F,K:");
scanf("%c",&a);
}

}

}

我只寫主要的程式,函式庫的部份,就看你用什麼版本的c

2007-10-13 18:55:56 補充:
if(a=='C'){
if(degree+273.15<0)
pfintf("輸入的溫度小於絕對0度\n");
}
else if(a=='F')
if((degree-32)*5/9+273.15<0)
pfintf("輸入的溫度小於絕對0度\n");
}
else if(a=='K')
if(degree<0)
pfintf("輸入的溫度小於絕對0度\n");

else if(a=='C'){
printf("F=%g,K=%g",(degree*9)/5+32,degree+273.15)
break;
}

.
.
.
.
前面再加這一段

2007-10-13 14:43:23 · answer #1 · answered by Sunnyblue1027 4 · 0 0

#include
#include
#define K(C) C+273
#define Ck(K) K-273
#define F(C) C*5/9+32
#define Cf(F) (F-32)*5/9
int main(int argc, char* argv[]){
//=====START=====//
double deg;
int opt;
printf("Input Degree: "),scanf("%lf",°);
printf("Options...\n1.Celsius\n2.Fahrenheit\n3.Kelvin\n(1/2/3):");
scanf("%d",&opt);
switch(opt){
case 1:
printf("Fahrenheit= %lf\nKelvin= %lf\n",F(deg),K(deg));
break;
case 2:
printf("Celsius= %lf\nKelvin= %lf\n",Cf(deg),K(Cf(deg)));
break;
case 3:
printf("Celsius= %lf\nFahrenheit= %lf\n",Ck(deg),F(Ck(deg)));
break;
default:
break;
}
//=====END=====//
system("PAUSE");
return 0;
}

2007-10-13 14:20:33 · answer #2 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers