Did you happen to know that Ruby has a free calculator? It can't do very complicated stuff, but it can do basic stuff, like addition and multiplication.
Addition
Just do a+b. To show the result, write a line like below:
print "19325325+123123247 is ", 19325325+123123247, ".\n"
Subtraction
Just do a-b. To show the result, write a line like below:
print "19325325-123123247 is ", 19325325-123123247, ".\n"
Multiplication
Just do a*b. To show the result, write a line like below:
print "19325325*123123247 is ", 19325325*123123247, ".\n"
Division
Just do a/b. To show the result, write a line like below:
print "19325325/123123247 is ", 19325325/123123247, ".\n"
Division with Remainder(Useful)
Just do a%b. To show the result, write a line like below: (Weird)
print "19325325%123123247 is ", 19325325%123123247, ".\n"
(You may want to change % to something like x divided by y is z.)
XSquared
Just do a**b. To show the result, write a line like above:
print "19325325**123123247 is ", 19325325**123123247, ".\n"
(You may not want to do this with such a big number)
P.S: Mind the space after the is or it will show up scrunched up.
SCREENSHOT:
Lesson File: Mediafire
Sincerely yours,
Admin
August 13, 2011
Subscribe to:
Post Comments (Atom)
Copyright © Learn Ruby! Step by Step Guides [EasyRuby]. All rights reserved.
Blogger template created by Templates Block in collaboration with Music Videos
Provided By Free Website Templates | Freethemes4all.com | Free Blogger Templates

No comments:
Post a Comment