Sha256: 5a285cf9fed9372e7a836c076493d25a74954dd576d6b573635cf1f312100725

Contents?: true

Size: 1 KB

Versions: 10

Compression:

Stored size: 1 KB

Contents

{{works with|Elixir|1.4}}
defmodule Arithmetic_Integer do
  # Function to remove line breaks and convert string to int
  defp get_int(msg) do
    IO.gets(msg) |> String.strip |> String.to_integer
  end
  
  def task do
    # Get user input
    a = get_int("Enter your first integer: ") 
    b = get_int("Enter your second integer: ")
    
    IO.puts "Elixir Integer Arithmetic:\n"
    IO.puts "Sum:            #{a + b}"
    IO.puts "Difference:     #{a - b}"
    IO.puts "Product:        #{a * b}"
    IO.puts "True Division:  #{a / b}"                  # Float
    IO.puts "Division:       #{div(a,b)}"               # Truncated Towards 0
    IO.puts "Floor Division: #{Integer.floor_div(a,b)}" # floored integer division
    IO.puts "Remainder:      #{rem(a,b)}"               # Sign from first digit
    IO.puts "Modulo:         #{Integer.mod(a,b)}"       # modulo remainder (uses floored division)
    IO.puts "Exponent:       #{:math.pow(a,b)}"         # Float, using Erlang's :math
  end
end

Arithmetic_Integer.task

Version data entries

10 entries across 7 versions & 1 rubygems

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