官术网_书友最值得收藏!

Integer arithmetic guide

Being able to compute mathematical equations in a program is a critical task for most programs in some form or another. In this section, we are going to see how to use integer arithmetic in Ruby.

Performing addition is as simple as a script like this:

p 5+5 

The same applies to subtraction, multiplication, and division. If you want to use exponents, you can use two asterisk symbols, like the following example, where the first 5 is the base integer and the second 5 is the exponent.

p 5**5 

The following is the list of arithmetic functions to use in a Ruby program:

  • +: This is used for addition
  • -: This is used for subtraction
  • /: This is used for division
  • *: This is used for multiplication
  • **: This is used for exponents
主站蜘蛛池模板: 奎屯市| 夏邑县| 和田县| 普陀区| 静宁县| 江都市| 仁化县| 鄂伦春自治旗| 鞍山市| 新沂市| 元谋县| 阜新市| 谷城县| 九寨沟县| 容城县| 湖南省| 仁布县| 民丰县| 永登县| 大兴区| 津南区| 临洮县| 泸西县| 德阳市| 宿州市| 诏安县| 涿州市| 渝北区| 东明县| 屏南县| 清原| 石河子市| 射洪县| 宝坻区| 锦屏县| 南靖县| 武乡县| 双峰县| 四平市| 吉林市| 黄冈市|