Convert temperature from Fahrenheit to Celsius

Problem statement:- Program to convert temperature from Fahrenheit to Celsius.

Data requirement:-

   Input Data:-fahrenheit

  Output Data:-
celsius

Program in C

Here is the source code of the C Program to Convert the temperature from Fahrenheit to Celsius.

Code:

#include<stdio.h>
int main()
{
    double fahrenheit,celsius;

    printf("Enter degree in Fahrenheit:");

    scanf("%lf",&fahrenheit);

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


    printf("Degree in Celsius is %0.2lf",celsius);

}

Input/Output:
Enter degree in Fahrenheit:98.7
Degree in Celsius is 37.06


Program in C++

Here is the source code of the C++ Program to Convert the temperature from Fahrenheit to Celsius.

Code:

#include<iostream>
using namespace std;
int main()
{
    double fahrenheit,celsius;
    cout<<"Enter degree in Fahrenheit:";
    cin>>fahrenheit;
    celsius= (fahrenheit-32)*5/9;
    cout<<"Degree in Celsius is "<<celsius;
}

Input/Output:
Enter degree in Fahrenheit:105
Degree in Celsius is 40.5556

Program in Java

Here is the source code of the Java Program to Convert the temperature from Fahrenheit to Celsius.

Code:

import java.util.Scanner;
public class FahrenheitToCelsius {

public static void main(String[] args) {

Scanner cs=new Scanner(System.in);
double fahrenheit, celsius;

    System.out.println("Enter degree in Fahrenheit:");

    fahrenheit=cs.nextDouble();

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


    System.out.println("Degree in Celsius is "+celsius);

cs.close();
}
}

Input/Output:
Enter degree in Fahrenheit:
99
Degree in Celsius is 37.22222222222222

Program in Python

Here is the source code of the Python Program to Convert the temperature from Fahrenheit to Celsius.

Code:

fahrenheit=int(input("Enter degree in fahrenheit: "))
celsius= (fahrenheit-32)*5/9;
print("Degree in celsius is",celsius)

Input/Output:
Enter degree in fahrenheit: 32
Degree in celsius is 0.0


Post a Comment

0 Comments