Anonymous user
Arithmetic/Integer: Difference between revisions
m
Changed over to headers.
No edit summary |
m (Changed over to headers.) |
||
Line 3:
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling.
==
with Ada.Text_Io;
with Ada.Integer_Text_IO;
Line 22 ⟶ 21:
end Integer_Arithmetic;
==
&&00p"=A",,:."=B ",,,00g.55+,v
v,+55.+g00:,,,,"A+B="<
Line 32 ⟶ 30:
==
#include <stdio.h>
#include <stdlib.h>
Line 66 ⟶ 63:
}
==
def arithmetic(a :int, b :int) {
Line 78 ⟶ 74:
}
==
To keep the example simple, the word takes the two numbers from the stack. '''/mod''' returns two results; the stack effect is ( a b -- a%b a/b ).
: arithmetic ( a b -- )
Line 89 ⟶ 84:
cr ." a mod b = " . cr ;
==
main = do
Line 105 ⟶ 99:
putStrLn $ "a / b = " ++ show (a `div` b)
==
import java.util.Scanner;
Line 122 ⟶ 115:
}
==
x = getKBValue prompt:"First number"
y = getKBValue prompt:"Second number:"
Line 134 ⟶ 126:
==
program arithmetic(input, output)
Line 149 ⟶ 140:
end.
==
my $a = <>;
Line 163 ⟶ 153:
;
==
;;; Setup token reader
Line 178 ⟶ 167:
printf(a mod b, 'a mod b = %p\n');
==
x = int(raw_input("Number 1: "))
Line 193 ⟶ 181:
raw_input( )
==
' Number 1: ' print expect 0 prefer as x
Line 205 ⟶ 192:
x y % " remainder: %d\n" print
==
puts 'Enter x and y'
Line 218 ⟶ 204:
"Remainder: #{x%y}"
==
(define (arithmetic x y)
Line 245 ⟶ 230:
(lcm 8 12) => 24
==
puts "Please enter two numbers:"
Line 270 ⟶ 254:
==
[ ( a b -- )
Line 282 ⟶ 265:
==
With external utilities:
|