Jump to content

Temperature conversion: Difference between revisions

Added Racket code
(Added Racket code)
Line 467:
222.2 Kelvin = -50.95 Celsius = -59.71 Fahrenheit = 399.96 Rankine degrees.
<value> <K/R/F/C> ? </lang>
 
=={{header|Racket}}==
Althoguh not exactly the shortest code, the converter function can turn any temperature into any other
<lang Racket>#lang racket
(define (converter temp init final)
(define to-k
(case init
('k temp)
('c (+ 273.15 temp))
('f (* (+ temp 459.67) 5/9))
('r (* temp 5/9))))
(case final
('k to-k)
('c (- to-k 273.15))
('f (- (* to-k 9/5) 459.67))
('r (* to-k 1.8))))
 
(define (kelvin-to-all temp)
(display (format "Kelvin: ~a \nCelsius: ~a \nFahrenheit: ~a \nRankine: ~a \n"
temp
(converter temp 'k 'c)
(converter temp 'k 'f)
(converter temp 'k 'r))))
(kelvin-to-all 21)
;Kelvin: 21
;Celsius: -252.14999999999998
;Fahrenheit: -421.87
;Rankine: 37.800000000000004
</lang>
 
=={{header|REXX}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.