Sha256: 9fea2fb2bb01b4e0066399b4049cd9449c17e9cfd1437fa333c3ccb6260c36c4

Contents?: true

Size: 943 Bytes

Versions: 10

Compression:

Stored size: 943 Bytes

Contents

{{works with|GNU Smalltalk}}
| a b |
'Input number a: ' display.
a := (stdin nextLine) asInteger.
'Input number b: ' display.
b := (stdin nextLine) asInteger.
('a+b=%1' % { a + b }) displayNl.
('a-b=%1' % { a - b }) displayNl.
('a*b=%1' % { a * b }) displayNl.
('a/b=%1' % { a // b }) displayNl.
('a%%b=%1' % { a \\ b }) displayNl.

{{works with|Smalltalk/X}} (and all other Smalltalks)
|a b|
a := (Dialog request:'Enter first number:') asNumber.
b := (Dialog request:'Enter second number:') asNumber.
#( + - / * // \\ quo: rem: raisedTo: **) do:[:operator |
    |result|
    result := a perform:operator with:b.
    '%P %s %P => %P\n' printf:{a . operator . b . result} on:Transcript
].
/ is exact division
<br>// is truncating division (towards negative infinity) 
<br>\\ is remainder from \\
<br>quo: is truncating division (towards zero) 
<br>\\ is remainder from quo:
<br>** is just an alias for raisedTo:
<p>Entering 10 and 3, generates:

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/smalltalk.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/smalltalk.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/smalltalk.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/smalltalk.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/smalltalk.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/smalltalk.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/smalltalk.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/smalltalk.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/smalltalk.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/smalltalk.txt