1115: 零起点学算法22——华氏摄氏温度转换
Description
输入一个华氏温度,根据公式C=(5/9)(F-32)计算对应的摄氏温度。
Input
输入一个华氏温度值(多组数据)
Output
输出输入的华氏温度和转换后的摄氏温度值。
输入格式请参考样例(每组数据一行)
" class="reference-link">Sample Input 
100
Sample Output
fahr=100.000000,celsius=37.777779
HINT
计算中所有数据使用 float 类型 注意 float 常量的写法
Source
零起点学算法
Code
#include<iostream>
#include<stdio.h>
#include <iomanip>
using namespace std;
int main()
{
float F;
while(~scanf("%f",&F))
{
float C=5*(F-32)/9;
cout.setf(ios::fixed);
cout<<"fahr="<<fixed<<setprecision(6)<<F<<",";
cout<<"celsius="<<fixed<<setprecision(6)<<C<<endl;
}
return 0;
}
还没有评论,来说两句吧...