Temperature conversion: Difference between revisions

Added Prolog
(Added Prolog)
(3 intermediate revisions by the same user not shown)
Line 664:
 
<pre>[celcius:-173.15 fahrenheit:-279.67 rankine:180.0]</pre>
 
=={{header|Asymptote}}==
<syntaxhighlight lang="Asymptote">void convKelvin(real K) {
write("K = " + string(K));
write("C = " + string(K - 273.15));
write("F = " + string((K - 273.15) * 1.8 + 32.0));
write("R = " + string(K * 1.8));
}
 
convKelvin(0.0);
write("");
convKelvin(21.0);</syntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 1,086 ⟶ 1,098:
PRINT "R = "; STR$(K * 1.8)
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Temperature conversion"
VERSION "0.001"
 
DECLARE FUNCTION Entry()
 
FUNCTION Entry()
DO
D$ = INLINE$("Kelvin degrees (>=0): ")
K = SBYTE(D$)
LOOP UNTIL K >= 0
 
PRINT "K = " + STR$(K)
PRINT "C = " + STR$(K - 273.15)
PRINT "F = " + STR$(K * 1.8 - 459.67)
PRINT "R = " + STR$(K * 1.8)
 
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 1,535 ⟶ 1,568:
R 37.80
</pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">double kelvinToCelsius(double k) {
return k - 273.15;
}
 
double kelvinToFahrenheit(double k) {
return k * 1.8 - 459.67;
}
 
double kelvinToRankine(double k) {
return k * 1.8;
}
 
void convertKelvin(double kelvin) {
print('K = ${kelvin.toStringAsFixed(2)}');
print('C = ${kelvinToCelsius(kelvin).toStringAsFixed(2)}');
print('F = ${kelvinToFahrenheit(kelvin).toStringAsFixed(2)}');
print('R = ${kelvinToRankine(kelvin).toStringAsFixed(2)}');
print('');
}
 
void main() {
convertKelvin(0.0);
convertKelvin(21.0);
}</syntaxhighlight>
 
=={{header|Delphi}}==
Line 4,105 ⟶ 4,164:
100 -173.15 -279.67 180
</pre>
 
=={{header|Prolog}}==
{{works with|GNU Prolog}}
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">convKelvin(Temp) :-
Kelvin is Temp,
Celsius is Temp - 273.15,
Fahrenheit is (Temp - 273.15) * 1.8 + 32.0,
Rankine is (Temp - 273.15) * 1.8 + 32.0 + 459.67,
format('~f degrees Kelvin~n', [Kelvin]),
format('~f degrees Celsius~n', [Celsius]),
format('~f degrees Fahrenheit~n', [Fahrenheit]),
format('~f degrees Rankine~n', [Rankine]).
 
test :-
convKelvin(0.0),
nl,
convKelvin(21.0).</syntaxhighlight>
 
=={{header|Pure Data}}==
2,169

edits