Program for Fahrenheit to Celsius conversion - GeeksforGeeks

07 Mar, 2022
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
C++
Java
Python3
C#
PHP
Javascript
/* Program in C to convert Degree Farenheit to Degree Celsuis */#include <stdio.h> //function to convert Degree Farenheit to Degree Celsuisfloat farenheit_to_celsius(float f){  return ((f - 32.0) * 5.0 / 9.0);} int main(){   float f = 40;   // passing parameter to function  printf("Temperature in Degree Celsius : %0.2f",farenheit_to_celsius(f));  return 0;}
// CPP program to convert Fahrenheit// scale  to Celsius scale#include <bits/stdc++.h>using namespace std; // function to convert// Fahrenheit to Celsiusfloat Conversion(float n){    return (n - 32.0) * 5.0 / 9.0;} // driver codeint main(){    float n = 40;    cout << Conversion(n);    return 0;}
// Java program to convert Fahrenheit// scale to Celsius scaleclass GFG {     // function to convert// Fahrenheit to Celsiusstatic float Conversion(float n){    return (n - 32.0f) * 5.0f / 9.0f;} // Driver codepublic static void main(String[] args) {    float n = 40;    System.out.println(Conversion(n));}} // This code is contributed by Anant Agarwal.
# Python3 program to convert Fahrenheit# scale to Celsius scale # function to convert# Fahrenheit to Celsiusdef Conversion(n):    return(n - 32.0) * 5.0 / 9.0 # driver coden = 40x = Conversion(n)print (x) # This article is contributed by Himanshu Ranjan
// c# program to convert Fahrenheit// scale to Celsius scaleusing System; class GFG {     // function to convert// Fahrenheit to Celsiusstatic float Conversion(float n){    return (n - 32.0f) * 5.0f / 9.0f;} // Driver codepublic static void Main(){    float n = 40;    Console.Write(Conversion(n));}} // This code is contributed by Nitin Mittal.
<?php// PHP program to convert Fahrenheit// scale to Celsius scale // function to convert// Fahrenheit to Celsiusfunction Conversion($n){    return ($n - 32.0) * 5.0 / 9.0;}     // Driver Code    $n = 40;    echo Conversion($n);     // This code is contributed by nitin mittal?>
<script> // Javascript program to convert Fahrenheit// scale to Celsius scale // function to convert// Fahrenheit to Celsiusfunction Conversion(n){    return (n - 32.0) * 5.0 / 9.0;} // driver code     let n = 40;    document.write(Conversion(n)); // This code is contributed Mayank Tyagi </script>
Output: 
4.44444
This article is contributed by Dibyendu Roy Chaudhuri. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
nitin mittal
mayanktyagi1709
sonawanejaydeep11
School Programming
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Interfaces in Java
C++ Classes and Objects
Operator Overloading in C++
Constructors in C++
Copy Constructor in C++
Overriding in Java
Polymorphism in C++
C++ Data Types
Constructors in Java
Different ways of Reading a text file in Java