Program for Celsius To Fahrenheit conversion
Last Updated :
17 Feb, 2023
Given a Temperature N on the Celsius scale, your task is to convert it into a Fahrenheit scale.
Examples:
Input: 0
Output: 32
Input: -40
Output: -40
The formula for converting the Celsius scale to the Fahrenheit scale is:
T(°F) = T(°C) × 9/5 + 32
Below is the implementation of the above idea.
C
#include <stdio.h>
float celsius_to_fahrenheit( float N)
{
return ((N * 9.0 / 5.0) + 32.0);
}
int main()
{
float N = 20.0;
printf ( "Temperature in Fahrenheit : %0.2f" ,
celsius_to_fahrenheit(N));
return 0;
}
|
C++
#include <bits/stdc++.h>
using namespace std;
float Cel_To_Fah( float N)
{
return ((N * 9.0 / 5.0) + 32.0);
}
int main()
{
float N = 20.0;
cout << Cel_To_Fah(N);
return 0;
}
|
Java
class GFG {
static float Cel_To_Fah( float N)
{
return ((N * 9 .0f / 5 .0f) + 32 .0f);
}
public static void main(String[] args)
{
float N = 20 .0f;
System.out.println(Cel_To_Fah(N));
}
}
|
Python3
def Cel_To_Fah(n):
return (n * 1.8 ) + 32
if __name__ = = "__main__" :
n = 20
print ( int (Cel_To_Fah(n)))
|
C#
using System;
class GFG {
static float Cel_To_Fah( float N)
{
return ((N * 9.0f / 5.0f) + 32.0f);
}
public static void Main()
{
float N = 20.0f;
Console.Write(Cel_To_Fah(N));
}
}
|
PHP
<?php
function Cel_To_Fah( $n )
{
return (( $n * 9.0 / 5.0) + 32.0);
}
$n = 20.0;
echo Cel_To_Fah( $n );
?>
|
Javascript
<script>
function Cel_To_Fah(n)
{
return ((n * 9.0 / 5.0) + 32.0);
}
let n = 20.0;
document.write(Cel_To_Fah(n));
</script>
|
Output
Temperature in Fahrenheit : 68.00
Time Complexity: O(1), as we are performing simple mathematical operations
Auxiliary Space: O(1), as we are not using any extra space
Share your thoughts in the comments
Please Login to comment...