Skip to content

Convert Celsius To Fahrenheit

Updated: at 02:09 AM

Table of contents

Open Table of contents

Write a program to convert celsius to fahrenheit

fahrerheit = (celsius * 9/5) + 32

Input ( C )  : -40
Output ( F ) : -40

C

// Write a C program to convert celsius to fahrenheit

#include<stdio.h>


float convertCtoF(float c)
{
    float f = 1.8*c + 32;
    return f;


}

int main()
{
    float celsius , fahrenheit;
    printf("Enter the temperature");
    scanf("%f", &celsius);

    fahrenheit = convertCtoF(celsius);
    printf("Fahrenheit value is %.2f" , fahrenheit);


}

C#

// Write a C# program to convert celsius to fahrenheit

using System;

class MainClass {
    public static void Main (string[] args) {
    Console.WriteLine ("Please enter the celcius : ");
    double celsius = Convert.ToDouble(Console.ReadLine());
    double fahrerheit = (celsius * 9/5) + 32;
    Console.WriteLine(+celsius+" celsius is "+fahrerheit+" fahrerheit");
  }
}

C++

// Write a C++ program to convert celsius to fahrenheit

#include <iostream>
using namespace std;

int main()
{
    int celsius,fahrenheit;
    cout<<"Input ( C ): ";
    cin>>celsius;
    fahrenheit = (celsius * 9/5) + 32;
    cout<<"Output ( F ): "<<fahrenheit;
    return 1;
}

F#

// Write a F# program to convert celsius to fahrenheit

let celciusToFahrenheit celsius : float =
  (celsius * 1.8) + 32.00

let fahrenheit =  celciusToFahrenheit -40.00

printfn "Equivalent fahrenheit : %f" fahrenheit

Go

// Write a Go program to convert celsius to fahrenheit

package main

import "fmt"

func main() {
	var celsius float64 = 0
	fmt.Printf("Enter temparature in celsius: \n")
	fmt.Scan(&celsius)

	fmt.Printf("Temparature in fahrenheit: %.2f", (celsius * 9.0/5.0) + 32.0)
}

Haskell

-- Write a Haskell program to convert celsius to fahrenheit

main :: IO ()
main = do
    putStrLn "Enter temperature in Celsius: "
    input <- getLine
    let celsius = read input :: Float

    let fahrenheit = (celsius * 9/5) + 32
    putStrLn $ "Given Celsius in Fahrenheit: " ++ show(fahrenheit) ++ " °F"

Java

// Write a Java program to convert celsius to fahrenheit

class ConvertCelsiusToFahrenheit {
    public static void main(String[] args) {
        int celsius = 100;
        System.out.println(CelciusToFahrenheit(celsius));
    }

    public static int CelciusToFahrenheit(int celsius){
        return (celsius * 9/5) + 32;
    }
}

JavaScript

// Write a JavaScript program to convert celsius to fahrenheit

function CelciusToFahrenheit(celsius) {
  //conversion function
  return (celsius * 9) / 5 + 32;
}

let celsius = -40;
console.log(CelciusToFahrenheit(celsius)); //-40

Julia

# Write a Julia program to convert celsius to fahrenheit

println("Enter value in celsius: ")
celsius = readline()
celsius = parse(Float64, celsius)
fahrenheit = round((celsius * 9/5) + 32; digits = 2)
println(celsius, " °C equals ", fahrenheit, " °F")

Kotlin

// Write a Kotlin program to convert celsius to fahrenheit

fun main() {
	val celsius = -40
	val fahrenheit = (celsius * 9 / 5) + 32
	println(fahrenheit)
}

Perl

# Write a Perl program to convert celsius to fahrenheit

use warnings;
use 5.010;

sub c_to_f {
  my($c)=@_;
  return ($c*9/5 )+32;
}


print "Input ( C ): ";
$celsius=<STDIN>;

$fahrenheit=c_to_f($celsius);
say "Output ( F ): $fahrenheit";

PHP

// Write a PHP program to convert celsius to fahrenheit

<?php

$celsius = -40;
$fahrenheit = ($celsius * 9 / 5) + 32;
echo $fahrenheit;

Python

# Write a Python program to convert celsius to fahrenheit

# program to convert celsius to fahrenheit

C = input("Input ( C )  : ")

if float(C) > -273.15:
    F = (float(C) * (9 / 5)) + 32

    f = "{0:.3g}".format(F)

    print(f"Output ( F )  : {f}")

else:
    print("Error: Invalid value provided for Celsius")

R

# Write a R program to convert celsius to fahrenheit

celsius = -40
fahrerheit = (celsius * 9/5) + 32
cat("fahrerheit: ", fahrerheit)

Ruby

# Write a Ruby program to convert celsius to fahrenheit

puts "Let's convert Celsius to Fahrenheit"
puts 'Insert the Celsius Temperature: '
celsius_input = gets.chomp.to_i
fahrenheit = (celsius_input * 9 / 5) + 32
puts "Temperature Converted: #{fahrenheit}"

Rust

// Write a Rust program to convert celsius to fahrenheit

// Convert celsius to fahrenheit
use std::io;
fn main() {
    println!("Enter the temperature in celsius");
    let mut celsius = String::new();
    io::stdin().read_line(&mut celsius).expect("Failed to read line");
    let celsius: f32 = celsius.trim().parse().expect("Please type a number!");
    let fahrenheit = (celsius * 1.8) + 32.0;
    println!("{}°C is {}°F", celsius, fahrenheit);
}

Scala

// Write a Scala program to convert celsius to fahrenheit

object HelloWorld {
	def main(args: Array[String]): Unit = {
	  val celsius = scala.io.StdIn.readInt();
	  println("fahrenheit: " + ((celsius * 9/5)+32) );
	}
}

Swift

// Write a Swift program to convert celsius to fahrenheit

import Swift
import Foundation

var celsius = -40
var fahrerheit = (celsius * 9/5) + 32
print("fahrerheit: ", fahrerheit)

TypeScript

// Write a TypeScript program to convert celsius to fahrenheit

function CelciusToFahrenheit(celsius: number): number {
  //conversion function
  return (celsius * 9) / 5 + 32;
}

const celsius: number = -40;
console.log(CelciusToFahrenheit(celsius)); //-40

Similar programs