Sha256: 9e0106ce2d4dcf53e9226dec2331a2b1ecd21b20e718dc8e58918c27652e82cc

Contents?: true

Size: 499 Bytes

Versions: 10

Compression:

Stored size: 499 Bytes

Contents

As F# is a functional language, we can easily create a list of pairs of the string name of a function and the function itself to iterate over printing the operation and applying the function to obtain the result:

do
  let a, b = int Sys.argv.[1], int Sys.argv.[2]
  for str, f in ["+", ( + ); "-", ( - ); "*", ( * ); "/", ( / ); "%", ( % )] do
    printf "%d %s %d = %d\n" a str b (f a b)

For example, the output with the arguments 4 and 3 is:

4 + 3 = 7
4 - 3 = 1
4 * 3 = 12
4 / 3 = 1
4 % 3 = 1

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/f_sharp|f#.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/f_sharp|f#.txt