섭씨 온도 'n'으로 주어진 과제는 주어진 온도를 화씨로 변환하여 표시하는 것입니다.
예시
Input 1-: 100.00 Output -: 212.00 Input 2-: -40 Output-: -40
온도를 섭씨에서 화씨로 변환하는 공식은 다음과 같습니다.
T(°F) =T(°C) × 9/5 + 32
여기서 T(°C)는 섭씨 온도이고 T(°F)는 화씨 온도입니다.
아래에 사용된 접근 방식은 다음과 같습니다.
- float 변수에 온도를 입력한다고 가정해 봅시다.
- 온도를 화씨로 변환하는 공식 적용
- 화씨 인쇄
알고리즘
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