Write predicates One converts centigrade
temperatures to Fahrenheit, the other checks if a
temperature is below freezing.
1. Conversion from Centigrade to Fahrenheit
The formula for converting Celsius to Fahrenheit is:
F = (C × 9/5) + 32
% Predicate to convert Centigrade to Fahrenheit
centigrade_to_fahrenheit(C, F) :-
F is (C * 9 / 5) + 32.
2. Checking if a temperature is below freezing
We can define freezing as 0°C, so this predicate will check if the temperature is below
freezing.
% Predicate to check if the temperature in Centigrade is below freezing (0°C)
below_freezing(C) :-
C < 0.
Example Queries:
1. To convert 25°C to Fahrenheit:
?- centigrade_to_fahrenheit(25, F).
Output:
F = 77.0
2. To check if -5°C is below freezing:
?- below_freezing(-5).
Output:
True.
3. To check if 10°C is below freezing:
?- below_freezing(10).
Output:
false.