formula to convert fahrenheit to celsius code example
Example 1: fahrenheit to celsius formula
cels = (fahr - 32.0) * 5.0/9.0;
fahr = (cels * 9.0/5.0) + 32.0;
Example 2: different formulas to convert celsius to fahrenheit
function fahrenheitToCelsius(fahrenheit) {
return (((fahrenheit - 32) * 5) / 9).toFixed(1);
}
function celsiusToFahrenheit(celsius) {
return ((9 * celsius) / 5 + 32).toFixed(1);
}
Example 3: convert fahrenheit to celsius
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int far = sc.nextInt();
int cel = (far - 32) * 5/9;
System.out.printf("%d Fahrenheit is %d Celsius", far, cel);
}
}
Example 4: celsius to fahrenheit formula
fahr = celsius * (9.0/5.0) + 32.0;