Arithmetic/Integer: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 881: | Line 881: | ||
console writeLine:a:" % ":b:" = ":(a mod:b). // matches sign of first operand |
console writeLine:a:" % ":b:" = ":(a mod:b). // matches sign of first operand |
||
].</lang> |
].</lang> |
||
=={{header|Elixir}}== |
|||
<lang Elixir> |
|||
# Function to remove line breaks and convert string to int |
|||
to_int = fn n -> n |> String.replace(~r/\n/,"") |> String.to_integer() end |
|||
# Get user input |
|||
a = IO.gets("Enter your first integer: ") |> to_int.() |
|||
b = IO.gets("Enter your second integer: ") |> to_int.() |
|||
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 "Remainder: #{rem(a,b)}" # Sign from first digit |
|||
IO.puts "Exponent: #{:math.pow(a,b)}" # Float, using Erlang's :math |
|||
</lang> |
|||
=={{header|Erlang}}== |
=={{header|Erlang}}== |