How to resolve the algorithm Temperature conversion step by step in the OCaml programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Temperature conversion step by step in the OCaml programming language
Table of Contents
Problem Statement
There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. The Fahrenheit and Rankine scales also have the same magnitude, but different null points. The Celsius/Kelvin and Fahrenheit/Rankine scales have a ratio of 5 : 9.
Write code that accepts a value of kelvin, converts it to values of the three other scales, and prints the result.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Temperature conversion step by step in the OCaml programming language
Source code in the ocaml programming language
let print_temp s t =
print_string s;
print_endline (string_of_float t);;
let kelvin_to_celsius k =
k -. 273.15;;
let kelvin_to_fahrenheit k =
(kelvin_to_celsius k)*. 9./.5. +. 32.00;;
let kelvin_to_rankine k =
(kelvin_to_celsius k)*. 9./.5. +. 491.67;;
print_endline "Enter a temperature in Kelvin please:";
let k = read_float () in
print_temp "K " k;
print_temp "C " (kelvin_to_celsius k);
print_temp "F " (kelvin_to_fahrenheit k);
print_temp "R " (kelvin_to_rankine k);;
You may also check:How to resolve the algorithm Padovan n-step number sequences step by step in the Nim programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the beeswax programming language
You may also check:How to resolve the algorithm Search a list step by step in the Raku programming language
You may also check:How to resolve the algorithm Spelling of ordinal numbers step by step in the Phix programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Pascal programming language