Cho nhiệt độ n độ C, chuyển sang độ F.
Ví dụ
Input: 100.00 → Output: 212.00 Input: -40 → Output: -40
Công thức: T(°F) = T(°C) × 9/5 + 32
Cách làm
- Nhập nhiệt độ Celsius vào biến float
- Áp dụng công thức chuyển đổi
- In kết quả Fahrenheit
Thuật toán
BẮT ĐẦU
Hàm chuyenDoi(float cel): fahr = (cel * 9/5) + 32, in kết quả
main(): Celsius = 100.00, gọi hàm
KẾT THÚC
Ví dụ mã C
#include <stdio.h>
void chuyenDoi(float cel){
float fahr = (cel * 9 / 5) + 32;
printf("%.2f Celsius = %.2f Fahrenheit", cel, fahr);
}
int main(){
float Celsius = 100.00;
chuyenDoi(Celsius);
return 0;
}
Kết quả C
100.00 Celsius = 212.00 Fahrenheit
Ví dụ mã C++
#include <bits/stdc++.h>
using namespace std;
float cToF(float n){
return ((n * 9.0 / 5.0) + 32.0);
}
int main(){
float n = 20.0;
cout << cToF(n);
return 0;
}
Kết quả C++
68