Integer comparison: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: Improved grammar in commentary.)
m (Spelling/grammar/aesthetics.)
Line 1: Line 1:
{{task}}{{basic data operation}}Get two integers from the user, and then output if the first one is less, equal or greater than the other. Test the condition ''for each case separately'', so that ''all three comparison operators are used'' in the code.
{{task}}
{{basic data operation}}
Get two integers from the user, and then output if the first one is less, equal or greater than the other. Test the condition ''for each case separately'', so that ''all three comparison operators are used'' in the code.


=={{header|Ada}}==
=={{header|Ada}}==
Line 75: Line 73:
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))
(t (format t "Cannot determine relevance between ~A and ~B!" a b)))))


After hitting enter, the REPL is expecting the two numbers right away. You can enter the two numbers, and the result will print immediately. Alternatively, you can wrap this code in a function definition:
After hitting enter, the REPL is expecting the two numbers right away. You can enter the two numbers, and the result will print immediately. Alternatively, you can wrap this code in a function definition:


(defun compare-integers ()
(defun compare-integers ()
Line 290: Line 288:
'''Interpreter:''' [[Perl]] 5.x
'''Interpreter:''' [[Perl]] 5.x


Seperate tests for less than, greater than, and equals
Separate tests for less than, greater than, and equals


sub test_num {
sub test_num {
Line 306: Line 304:
};
};


All three tests in one. if $f is less than $s return -1, greater than return 1, equal to return 0
All three tests in one. If $f is less than $s return -1, greater than return 1, equal to return 0


sub test_num {
sub test_num {