Tuesday, February 18, 2014

Playing with Numbers in Ruby

Using Numbers in Ruby - Source for the tutorial is Ruby Programming Language
by Yukihiro Matsumoto(creator of Ruby) and David Flanagan.

The blog below has a sample code with output. The sample code below with inline comments in a way summarizes the concept(refer blog title) covered as part of the book.

20
6
50
Subtraction of 50 - 30 is: 20
Exponentiation of 3^3 is: 27
Value of 5 modulo 3 is: 2
view raw numbers in ruby hosted with ❤ by GitHub
# playing with numbers.. Checking the general backslashes to be run..
puts( 4 * 5)
puts("\n")
# This is not allowed..I guess.. puts (100/20) puts("\t") puts(20 + 30)
puts (100/20 + 90/54)
puts("\t")
puts(20 + 30)
# Escape sequences and all need to be given with double quotes not single quotes.. puts("\n")
puts("\n")
num = 50 - 30
puts("Subtraction of 50 - 30 is: \t #{num}")
num1 = 3**3
puts("Exponentiation of 3^3 is: \t #{num1}")
num2 = 5%3 # Modulo in operation.. do note..
puts("Value of 5 modulo 3 is: \t #{num2}")


No comments:

Post a Comment