C语言编写华氏温度计和摄氏温度及的转换

作者:追风筝的人 | 创建时间: 2023-06-08
转换有个公式:c=(5/9)*(f-32) 有公式就好办了,简单的代码...
C语言编写华氏温度计和摄氏温度及的转换

操作方法

首先打开VC++

文件》》新建

新建一个C++文档

声明头文件和变量 #include<stdio.h> char cmd; float temperature;

主要代码,先进行选择,是华氏还是摄氏,然后用公式转化 while(1) { printf("\n*****************************************\n"); printf("\n|   Please select one of convertions:   |\n"); printf("|    c:  Convert Celsius to Fahrenheit  |\n"); printf("|    f:  Convert Fahrenheit to Celsius  |\n"); printf("|    q:  Quit                           |\n"); printf("\n*****************************************\n"); scanf("%c",&cmd); switch (cmd) { case 'c': { printf("\n*****************************************\n"); printf("\n|   Please input Celsius temperature:   |\n"); scanf("%f",&temperature); printf("\n|  The Fahrenheit temperature is:%6.3f|\n",temperature*1.8+32); printf("\n*****************************************\n"); break; } case 'f': { printf("\n*****************************************\n"); printf("\n  Please input Fahrenheit temperature:  |\n"); scanf("%f",&temperature); printf("\n  The Celsius temperature is : %6.3f  |\n",5*(temperature-32)/9); printf("\n*****************************************\n"); break; } case 'q': { break; } default: { printf("Your Command Error!temperatureut Again\n"); } } getchar(); if(cmd=='q') break; printf("\n   Please input any key to use again:   \n"); getchar(); } return 0;

运行结果

点击展开全文

更多推荐