c语言华氏和摄氏温度的转换 如何编写一个华氏摄氏度与摄氏温度之间的C语言转换程序?
\u7528C\u8bed\u8a00\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff1a\u534e\u6c0f\u6e29\u5ea6\u548c\u6444\u6c0f\u6e29\u5ea6\u7684\u8f6c\u6362\u516c\u5f0f\u4e3ac=(f-32)/1.8\uff0c;\u8fd9\u4e2a\u662fc++\u7684 \u697c\u4e3b\u597d\u50cf\u5199\u9519\u516c\u5f0f\u4e86\uff0c f\u4ee3\u8868\u534e\u6c0f\u6e29\u5ea6\uff0cc\u4ee3\u8868\u6444\u6c0f\u6e29\u5ea6
#include
#include
void main()
{
double f,c,b;
cout<<"\u8bf7\u8f93\u5165\u534e\u6c0f\u6e29\u5ea6:"<<endl;
cin>>f;
cout<<"\u5bf9\u5e94\u7684\u6444\u6c0f\u6e29\u5ea6\u4e3a:"<<endl;
c=f-32;
b=5.00/9;
c=b*c;
cout<<setiosflags(ios::fixed)<<setprecision(2)<<"c="<<c<<endl;
}
\uff1b\u518d\u7ed9\u4f60\u4e2ac\u8bed\u8a00\u7684
#include
void main()
{
double f,c,b;
scanf("\u8bf7\u8f93\u5165\u534e\u6c0f\u6e29\u5ea6: %f\n",&f);
c=f-32;
b=5.00/9;
c=b*c;
printf("\u5bf9\u5e94\u7684\u6444\u6c0f\u6e29\u5ea6\u4e3a: %f\n",c);
}
C\u8bed\u8a00\u7a0b\u5e8f\uff1a
#include int main(){double f, c;printf("\u8bf7\u8f93\u5165\u6444\u6c0f\u6e29\u5ea6\u503c\uff1a");scanf("%lf", &c);f = 9.0 / 5 * c + 32;printf("\u534e\u6c0f\u6e29\u5ea6\u503c\uff1a%lf\n", f);printf("\u8bf7\u8f93\u5165\u534e\u6c0f\u6e29\u5ea6\u503c\uff1a");scanf("%lf", &f);c = (f - 32) * 5 / 9;printf("\u6444\u6c0f\u6e29\u5ea6\u503c\uff1a%lf\n", c);return 0;}
\u8fd0\u884c\u6d4b\u8bd5\uff1a
\u8bf7\u8f93\u5165\u6444\u6c0f\u6e29\u5ea6\u503c\uff1a35\u534e\u6c0f\u6e29\u5ea6\u503c\uff1a95.000000\u8bf7\u8f93\u5165\u534e\u6c0f\u6e29\u5ea6\u503c\uff1a95\u6444\u6c0f\u6e29\u5ea6\u503c\uff1a35.000000
你好,测试通过
请采纳!
#include<stdio.h>
void main()
{
float C,F; //改为float
for(F=0;F<=300;F+=20)
{
C=(5.0/9)*(F-32); //5.0 转化成double
printf("%4.0f%10.1f
",F,C);
}
}
#include<stdio.h>
void main()
{
float C,F; //变量类型
for(F=0;F<=300;F+=20)
{
C=(5/9.0)*(F-32); //转换类型
printf("%4.0f%10.1f
",F,C);
}
}
0 -17.8
20 -6.7
40 4.4
60 15.6
80 26.7
100 37.8
120 48.9
140 60.0
160 71.1
180 82.2
200 93.3
220 104.4
240 115.6
260 126.7
280 137.8
300 148.9
Press any key to continue
c和f的类型应为浮点类型float或double
5/9答案是0,你应该这样写:C=(5.0/9)*(F-32)
绛旓細鍗庢皬搴︿笌鎽勬皬搴︾殑杞寲鏄憚姘忓害=锛堝崕姘忓害-32锛*5/9銆傜敤c璇█鏉ヨ〃绀烘椂锛屼竴瀹氳娉ㄦ剰鍗庢皬搴﹀拰鎽勬皬搴﹂兘瀹氫箟涓哄疄鍨嬨傚洜涓篶璇█瑙勫畾锛屾暣鍨嬫暟鎹棿杩涜杩愮畻锛岀粨鏋滃彧鑳戒负鏁村瀷锛屽氨浼氬奖鍝嶆渶鍚庣殑缁撴灉銆侰璇█ 涓闂ㄩ潰鍚戣繃绋嬬殑銆佹娊璞″寲鐨勯氱敤绋嬪簭璁捐璇█锛屽箍娉涘簲鐢ㄤ簬搴曞眰寮鍙戙侰璇█鑳戒互绠鏄撶殑鏂瑰紡缂栬瘧銆佸鐞嗕綆绾у瓨鍌...
绛旓細鎽勬皬娓╁害锛堚剝锛夊拰鍗庢皬娓╁害锛堚剦锛変箣闂寸殑鎹㈢畻鍏崇郴涓猴細 鍗庢皬搴=鎽勬皬搴γ1.8+32 鎽勬皬搴=(鍗庢皬搴-32)梅1.8 5(鍗庢皬搴-50)=9(鎽勬皬搴-10)銆傛敞鎰忥細鑻涓哄崕姘忔俯搴︼紝C涓烘憚姘忔俯搴︼紝鍒欒浆鎹㈠叕寮忎负C=5/9 (F−32)锛岃緭鍑虹粨鏋滃彇2浣嶅皬鏁般傜壒鍒敞鎰忓叕寮忚浆鎹负C璇█琛ㄨ揪寮忔椂鐨勬纭с傝瑷-璁$畻鎽勬皬娓...
绛旓細鐢–璇█鎵撳嵃杈撳嚭鍗庢皬娓╁害杞憚姘忔俯搴︾殑鍑犵鏂规硶 鍒╃敤鍏紡鈩=锛5/9锛*锛堚剦-32锛変互vc++6.0涓轰緥銆 棣栧厛杩愯vc++6.0 杩涜缂栫▼锛屽熀鏈濊矾濡備笅锛氬畾涔夊彉閲忊啋鍙橀噺璧嬪尖啋while寰幆鈫掕緭鍑烘暟鎹 娉ㄦ剰杈撳嚭鏁版嵁鐨勬帓鍒楁柟寮忥細鍒╃敤杞箟瀛楃'\n'锛堝洖杞︽崲琛岋級銆'\t'锛堣烦鍒颁笅涓鍒惰〃绗︼級娓╁害杞崲涓鑸兘涓嶆槸鏁存暟锛岃嫢鎯...
绛旓細鐩存帴杈撳嚭缁撴灉锛屼互涓嬫槸浣跨敤C璇█灏鍗庢皬娓╁害杞崲涓鎽勬皬娓╁害鐨浠g爜鐗囨锛氬綋闇瑕佸湪C璇█涓灏嗕竴涓崕姘忔俯搴﹁浆鎹负鎽勬皬娓╁害鏃讹紝鍙互浣跨敤鍏紡C=5.0/9.0*(F-32)锛屽叾涓瑿琛ㄧず鎽勬皬娓╁害锛孎琛ㄧず鍗庢皬娓╁害銆備笅闈㈡槸涓涓ず渚嬬▼搴忥紝灞曠ず浜嗗浣曞疄鐜拌繖涓杞崲锛歩nclude<stdio.h>voidmain(){floatF,C;printf("璇疯緭鍏ュ崕姘忔俯...
绛旓細鎮ㄥソ锛屽緢楂樺叴鍥炵瓟鎮ㄧ殑闂銆鍗庢皬搴︿笌鎽勬皬搴︾殑杞寲鏄憚姘忓害=锛堝崕姘忓害-32锛*5/9銆傜敤c璇█鏉ヨ〃绀烘椂锛屼竴瀹氳娉ㄦ剰鍗庢皬搴﹀拰鎽勬皬搴﹂兘瀹氫箟涓哄疄鍨嬨傚洜涓篶璇█瑙勫畾锛屾暣鍨嬫暟鎹棿杩涜杩愮畻锛岀粨鏋滃彧鑳戒负鏁村瀷锛屽氨浼氬奖鍝嶆渶鍚庣殑缁撴灉銆
绛旓細浣犲ソ锛侊紒璇风湅浠g爜锛屾弧鎰忚閲囩撼锛歩nclude<stdio.h>int main(){int x; float a,s; printf("璇烽夋嫨杞崲鐨勭被鍨嬶細\n 鍗庢皬杞鎽勬皬锛1锛塡n 鎽勬皬杞崕姘忥紙2锛塡n"); scanf("%d",&x); switch(x) { case 1: printf("鍗庢皬娓╁害:"); scanf("%f",&a); s=(a-32)/1...
绛旓細鍥炵瓟锛氬湪while璇彞涓婇潰鍔犱竴涓緭鍑鸿鍙ヤ緥:printf("fahr celsius\n")浠ュ悗鍏卞悓瀛︿範鍟婃湁浠涔堜笉鎳傜殑鍙互缁х画闂晩350608412
绛旓細褰撻渶瑕佸湪C璇█缂栫▼涓皢鍗庢皬娓╁害杞崲涓鎽勬皬娓╁害鏃讹紝鍙互鎸夌収鎻愪緵鐨勫叕寮廲=5*(F-32)/9鏉ュ疄鐜般備互涓嬫槸涓涓畝鍗曠殑绀轰緥浠g爜锛屽府鍔╀綘鐞嗚В濡備綍鎿嶄綔锛氶鍏堬紝浣犻渶瑕佸寘鍚ご鏂囦欢锛屽畠鍖呭惈浜嗚緭鍏ュ拰杈撳嚭鍔熻兘鐨勫0鏄庛傚湪main鍑芥暟涓紝瀹氫箟涓や釜娴偣鍨嬪彉閲廲鍜宖锛屽垎鍒瓨鍌鎽勬皬鍜屽崕姘忔俯搴:c#includeintmain(void){鐒跺悗锛屾彁绀...
绛旓細鎽勬皬娓╂爣锛埪癈锛夊拰鍗庢皬娓╂爣锛埪癋锛変箣闂鐨勬崲绠鍏崇郴涓猴細F=C脳1.8+32銆侰=(F-32)梅1.8銆C璇█鏄竴闂ㄩ潰鍚戣繃绋嬬殑銆佹娊璞″寲鐨勯氱敤绋嬪簭璁捐璇█锛屽箍娉涘簲鐢ㄤ簬搴曞眰寮鍙戙侰璇█鑳戒互绠鏄撶殑鏂瑰紡缂栬瘧銆佸鐞嗕綆绾у瓨鍌ㄥ櫒銆侰璇█鏄粎浜х敓灏戦噺鐨勬満鍣ㄨ瑷浠ュ強涓嶉渶瑕佷换浣曡繍琛岀幆澧冩敮鎸佷究鑳借繍琛岀殑楂樻晥鐜囩▼搴忚璁¤瑷銆傚敖绠...
绛旓細鍏充簬鍗庢皬娓╁害鍜屾憚姘忔俯搴鎹㈢畻鍏紡c璇█锛屽崕姘忔俯搴﹀拰鎽勬皬娓╁害鎹㈢畻鍏紡杩欎釜寰堝浜鸿繕涓嶇煡閬擄紝浠婂ぉ鏉ヤ负澶у瑙g瓟浠ヤ笂鐨勯棶棰橈紝鐜板湪璁╂垜浠竴璧锋潵鐪嬬湅鍚э紒1銆佷簩鑰呴棿鐨勬崲绠鍏紡濡備笅锛 鎽勬皬锛5/9锛埪癋锛32锛 渚嬪锛氬皢鍗庢皬90搴︽崲绠鎴愭憚姘忓害鏁 5/9脳锛90锛32锛夛紳5/9脳58锛32.2 鍗筹細鍗庢皬掳F锛濃剝脳9/5锛32 ...