Celsius to Fahrenheit Conversion
Problem Description​
Given a temperature in celsius C. You have to convert it in Fahrenheit.
Examples​
Example 1:
Input:
C = 32
Output:
89.60
Explanation:
For 32 degree C temperature
in farenheit = 89.60
Example 2:
Input:
C = 25
Output:
77.00
Explanation:
For 25 degree C temperature
in farenheit = 77.
Constraints​
1 ≤ C ≤ 100000
Solution for Celsius to Fahrenheit Conversion​
Code in Different Languages​
- Python
- Java
- C++
class Solution:
def celciusToFahrenheit(self, C: int) -> float:
# code here
return C * 9 / 5 + 32
# Example usage
solution = Solution()
print(solution.celciusToFahrenheit(0)) # 32.0
print(solution.celciusToFahrenheit(100)) # 212.0
class Solution {
public double celciusToFahrenheit(int C) {
// code here
return (double) C * 9 / 5 + 32;
}
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.celciusToFahrenheit(0)); // 32.0
System.out.println(solution.celciusToFahrenheit(100)); // 212.0
}
}
class Solution{
public:
double celciusToFahrenheit(int C){
//code here
return (double) C * 9 / 5 + 32;
}
};
References​
- GeekForGeeks Problem: Celsius to Fahrenheit Conversion