Jump to content

Arithmetic/Integer: Difference between revisions

Line 2,193:
if -d- /hasvalue yes goto :a else goto :end
:end</lang>
 
=={{header|Prolog}}==
 
Integer quotient (`//`) rounds towards 0.
 
Remainder (`rem`) matches the sign of its first operand.
 
<lang prolog>
 
print_expression_and_result(M, N, Operator) :-
Expression =.. [Operator, M, N],
Result is Expression,
format('~w ~8|is ~d~n', [Expression, Result]).
 
arithmetic_integer :-
read(M),
read(N),
maplist( print_expression_and_result(M, N), [+,-,*,//,rem,^] ).
 
</lang>
 
Use thus:
 
<lang prolog>
?- arithmetic_integer.
|: 5.
|: 7.
5+7 is 12
5-7 is -2
5*7 is 35
5//7 is 0
5 rem 7 is 5
5^7 is 78125
true.
</lang>
 
=={{header|PureBasic}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.