雅思作文写作格式:C语言编程:输入一个华氏温度,要求输出摄氏温度,公式为:
来源:百度文库 编辑:神马品牌网 时间:2024/10/02 22:24:06
输入一个华氏温度,要求输出摄氏温度,公式为:C=(5/9)*(F-12),
输出要有文字说明,取2位小数。
谢谢了!!!
#include <stdio.h>int main(){ double c, f; printf ("请输入华氏温度:"); scanf ("%lf", &f); c=5.0/9*(f-32); printf ("%g华氏温度是%.2f摄氏温度\n", f, c); return 0;}
扩展资料:
#include<iostream>
using namespace std;
int main()
{
float f,c;
cout<<"请输入华氏温度:";
cin>>f;
c=5*(f-32)/9;
cout<<"摄氏温度为:"<<c<<endl;
return 0;
}
根据华氏温度与摄氏温度的公式,设计代码如下:
#include<stdio.h>
int main()
{
double c,f;
scanf("%lf",&f);
c=5*(f-32)/9;
printf("c=%.2lf",c);
}
扩展资料:
输入摄氏温度一个转换为华氏温度的代码如下:
#include <stdio.h>
void main()
{
float F,C;
printf("请输入您需要转换的摄氏温度:");
scanf("%f",&C);
F = (C+32)*9/5.0;
printf("其对应的华氏温度为:%.2f \n",F);
}
参考资料:百度百科-printf
#include <stdio.h>
#include<ctype.h>
void main()
{
double celsius=0.0;
double fahrenheit=0.0;
double celsius_to_fahrenheit=0.0;
double fahrenheit_to_celsius=0.0;
char choose=0;
printf("请选择你要查询的温度计量单位 摄氏度(C)和 华氏度(F):"); scanf("%c",&choose);
switch(toupper(choose))
{
case 'C':
printf("\n请输入摄氏温度: ");
scanf("%lf",&celsius);
if(celsius)
celsius_to_fahrenheit=celsius*1.8+32;
printf("\n摄氏 %.2lf 度 转换成 华氏 %.2lf 度 \n\n",celsius,celsius_to_fahrenheit);
break;
case 'F':
printf("\n请输入华氏温度: ");
scanf("%lf",&fahrenheit);
if(fahrenheit)
fahrenheit_to_celsius=(fahrenheit-32)*5/9;
printf("\n华氏 %.2lf 度 转换成 摄氏 %.2lf 度 \n\n",fahrenheit,fahrenheit_to_celsius);
break;
default:
printf("\n\a输入错误 请重新尝试!\n\n");
}
}
标准答案:
#include<stdio.h>
main()
{
double tem_c, tem_f;
puts("=====华氏温度至摄氏温度转换程序=====");
printf("请输入华氏温度:");
scanf("%lf", &tem_f);
tem_c = (tem_f - 12) * 5.0 / 9.0;
printf("%f对应的摄氏温度为%.2f", tem_f, tem_c);
renturn 0;
}
顺手写的,没有上机试.
#include <stdio.h>
void main()
{
float c,f;
printf("请输入一个华氏温度\n");
scanf("%f",&f);
c=(f-32)*5/9;
printf("它的摄氏温度为:%.2f",c);
}