Program to Convert From Fahrenheit to Celsius

Program to Convert From Fahrenheit to Celsius

  • Write a program to Convert From Fahrenheit to Celsius in C
  • Write a program to Convert From Fahrenheit to Celsius in C++
  • Write a program to Convert From Fahrenheit to Celsius in Python
  • Write a program to Convert From Fahrenheit to Celsius in PHP
  • Write a program to Convert From Fahrenheit to Celsius in Java
  • Write a program to Convert From Fahrenheit to Celsius in Java Script
  • Write a program to Convert From Fahrenheit to Celsius in C#

Explanation:

The following formula can be used to convert a temperature from Fahrenheit (°F) to Celsius (°C):

Celsius = (Fahrenheit – 32​) x (5/9)

Steps to Convert

  1. Take the input temperature in Fahrenheit (F).
  2. Subtract 32 from F.
  3. Multiply the result by 5/9 (or approximately 0.5556).
  4. The result is the temperature in Celsius (C).

Program to Convert From Fahrenheit to Celsius

#include <stdio.h>

int main() {
    float fahrenheit, celsius;

    // Input Fahrenheit value
    printf("Enter temperature in Fahrenheit: ");
    scanf("%f", &fahrenheit);

    // Convert to Celsius
    celsius = (fahrenheit - 32) * 5 / 9;

    // Output the result
    printf("Temperature in Celsius: %.2f\n", celsius);

    return 0;
}

#include <iostream>
using namespace std;

int main() {
    float fahrenheit, celsius;

    // Input Fahrenheit value
    cout << "Enter temperature in Fahrenheit: ";
    cin >> fahrenheit;

    // Convert to Celsius
    celsius = (fahrenheit - 32) * 5 / 9;

    // Output the result
    cout << "Temperature in Celsius: " << celsius << endl;

    return 0;
}

fahrenheit = float(input("Enter temperature in Fahrenheit: "))

# Convert to Celsius
celsius = (fahrenheit - 32) * 5 / 9

# Output the result
print(f"Temperature in Celsius: {celsius:.2f}")

<?php
// Input Fahrenheit value
$fahrenheit = (float)readline("Enter temperature in Fahrenheit: ");

// Convert to Celsius
$celsius = ($fahrenheit - 32) * 5 / 9;

// Output the result
echo "Temperature in Celsius: " . number_format($celsius, 2) . "\n";
?>

import java.util.Scanner;

public class FahrenheitToCelsius {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Input Fahrenheit value
        System.out.print("Enter temperature in Fahrenheit: ");
        double fahrenheit = scanner.nextDouble();

        // Convert to Celsius
        double celsius = (fahrenheit - 32) * 5 / 9;

        // Output the result
        System.out.printf("Temperature in Celsius: %.2f\n", celsius);

        scanner.close();
    }
}

let fahrenheit = parseFloat(prompt("Enter temperature in Fahrenheit: "));

// Convert to Celsius
let celsius = (fahrenheit - 32) * 5 / 9;

// Output the result
console.log(`Temperature in Celsius: ${celsius.toFixed(2)}`);

using System;

class Program {
    static void Main() {
        // Input Fahrenheit value
        Console.Write("Enter temperature in Fahrenheit: ");
        double fahrenheit = Convert.ToDouble(Console.ReadLine());

        // Convert to Celsius
        double celsius = (fahrenheit - 32) * 5 / 9;

        // Output the result
        Console.WriteLine($"Temperature in Celsius: {celsius:F2}");
    }
}

List of All Programs