C++ 中摄氏度转换为华氏度的程序
给出摄氏度的温度 'n',挑战是将给定的温度转换为华氏度并显示它。
比如
Input 1-: 100.00 Output -: 212.00 Input 2-: -40 Output-: -40
从摄氏度转换为华氏度的温度有以下公式
T(°F) = T(°C) × 9/5 + 32
其中,T(°C) 是摄氏度温度,T(°F) 是华氏度温度
下面使用的算法如下
- 输入浮点变量中的温度,记为摄氏度
- 应用公式将温度转换为华氏度
- 打印华氏度
算法
Start Step 1 -> Declare a function to convert Celsius to Fahrenheit void cal(float cel) use formula float fahr = (cel * 9 / 5) + 32 print cel fahr Step 2 -> In main() Declare variable as float Celsius Call function cal(Celsius) Stop
使用 C 语言
比如
#include <stdio.h>
//convert Celsius to fahrenheit
void cal(float cel){
float fahr = (cel * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit", cel, fahr);
}
int main(){
float Celsius=100.00;
cal(Celsius);
return 0;
}输出
100.00 Celsius = 212.00 Fahrenheit
使用 C++ 语言
比如
#include <bits/stdc++.h>
using namespace std;
float cel(float n){
return ((n * 9.0 / 5.0) + 32.0);
}
int main(){
float n = 20.0;
cout << cel(n);
return 0;
}输出
68
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP