Convert Celsius to Fahrenheit

Hi Guys, Welcome to Proto Coders Point, In this article let’s checkout how to convert celsius to fahrenheit in all programming languages.

Here is a formula to convert a temperature from Celsius to Fahrenheit:

°F = (°C x 1.8) + 32

The temperature is expressed in degrees Celsius and degrees Fahrenheit in the equations above, respectively.

We have Temperature in form of Celsius, By using above formula, first simple multiple the Celsius temperature by 1.8 & then add 32. The Total we get is the temperature in Fahrenheit unit.

Example

To convert a temperature of 31 degrees Celsius to Fahrenheit, the formula used is as follows:

°F = (31 x 1.8) + 32 
°F = 55.8 + 32
°F = 87.8

Therefore, we get result after converting 30 degrees Celsius is equivalent to 87.8 degrees in Fahrenheit.


C Program to convert a temperature in Celsius to Fahrenheit

#include <stdio.h>

int main() {
    float celsius, fahrenheit;

    printf("Enter temperature in Celsius: ");
    scanf("%f", &celsius);

    fahrenheit = (celsius * 1.8) + 32;

    printf("%.2f Celsius is equivalent to %.2f Fahrenheit", celsius, fahrenheit);

    return 0;
}

C++ Program to convert a temperature in Celsius to Fahrenheit

#include <iostream>
using namespace std;

int main() {
    float celsius, fahrenheit;

    cout << "Enter temperature in Celsius: ";
    cin >> celsius;

    fahrenheit = (celsius * 1.8) + 32;

    cout << celsius << " Celsius is equivalent to " << fahrenheit << " Fahrenheit" << endl;

    return 0;
}

Java Program to convert a temperature in Celsius to Fahrenheit

import java.util.Scanner;

public class CelsiusToFahrenheit {
    public static void main(String[] args) {
        float celsius, fahrenheit;

        Scanner input = new Scanner(System.in);

        System.out.print("Enter temperature in Celsius: ");
        celsius = input.nextFloat();

        fahrenheit = (celsius * 1.8f) + 32;

        System.out.printf("%.2f Celsius is equivalent to %.2f Fahrenheit", celsius, fahrenheit);
    }
}

Python Program to convert a temperature in Celsius to Fahrenheit

celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 1.8) + 32
print("{:.2f} Celsius is equivalent to {:.2f} Fahrenheit".format(celsius, fahrenheit))

Javascript Program to convert a temperature in Celsius to Fahrenheit

let celsius = parseFloat(prompt("Enter temperature in Celsius: "));
let fahrenheit = (celsius * 1.8) + 32;
console.log(celsius + " Celsius is equivalent to " + fahrenheit.toFixed(2) + " Fahrenheit");

Dart Program to convert a temperature in Celsius to Fahrenheit

import 'dart:io';

void main() {
  stdout.write('Enter temperature in Celsius: ');
  double celsius = double.parse(stdin.readLineSync()!);

  double fahrenheit = (celsius * 1.8) + 32;

  print('$celsius Celsius is equivalent to ${fahrenheit.toStringAsFixed(2)} Fahrenheit');
}

GO Language Program to convert a temperature in Celsius to Fahrenheit

package main

import (
	"fmt"
)

func main() {
	var celsius float64
	fmt.Print("Enter temperature in Celsius: ")
	fmt.Scanln(&celsius)

	fahrenheit := (celsius * 1.8) + 32

	fmt.Printf("%.2f Celsius is equivalent to %.2f Fahrenheit", celsius, fahrenheit)
}

Kotlin Program to convert a temperature in Celsius to Fahrenheit

fun main() {
    print("Enter temperature in Celsius: ")
    val celsius = readLine()!!.toFloat()

    val fahrenheit = (celsius * 1.8) + 32

    println("%.2f Celsius is equivalent to %.2f Fahrenheit".format(celsius, fahrenheit))
}