Program for Fahrenheit to Celsius conversion
Given a Temperature n in Fahrenheit scale convert it into Celsius scale .
Examples:
Input : 32
Output : 0
Input :- 40
Output : -40
Formula for converting Fahrenheit scale to Celsius scale
T(°C) = (T(°F) - 32) × 5/9
C
#include <stdio.h>
float fahrenheit_to_celsius( float f)
{
return ((f - 32.0) * 5.0 / 9.0);
}
int main()
{
float f = 40;
printf ( "Temperature in Degree Celsius : %0.2f" ,fahrenheit_to_celsius(f));
return 0;
}
|
C++
#include <bits/stdc++.h>
using namespace std;
float Conversion( float n)
{
return (n - 32.0) * 5.0 / 9.0;
}
int main()
{
float n = 40;
cout << Conversion(n);
return 0;
}
|
Java
class GFG {
static float Conversion( float n)
{
return (n - 32 .0f) * 5 .0f / 9 .0f;
}
public static void main(String[] args) {
float n = 40 ;
System.out.println(Conversion(n));
}
}
|
Python3
def Conversion(n):
return (n - 32.0 ) * 5.0 / 9.0
n = 40
x = Conversion(n)
print (x)
|
C#
using System;
class GFG {
static float Conversion( float n)
{
return (n - 32.0f) * 5.0f / 9.0f;
}
public static void Main()
{
float n = 40;
Console.Write(Conversion(n));
}
}
|
PHP
<?php
function Conversion( $n )
{
return ( $n - 32.0) * 5.0 / 9.0;
}
$n = 40;
echo Conversion( $n );
?>
|
Javascript
<script>
function Conversion(n)
{
return (n - 32.0) * 5.0 / 9.0;
}
let n = 40;
document.write(Conversion(n));
</script>
|
Output:
4.44444
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
14 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...