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

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
主站蜘蛛池模板: 怀安县| 渭南市| 来安县| 平罗县| 南漳县| 自贡市| 闵行区| 宁陕县| 确山县| 象州县| 文安县| 灌云县| 玉环县| 华池县| 尉犁县| 云浮市| 锡林浩特市| 平舆县| 马边| 庐江县| 民勤县| 卢氏县| 禹州市| 徐州市| 枣庄市| 体育| 六枝特区| 吉水县| 凤翔县| 佛教| 简阳市| 英吉沙县| 江都市| 抚顺县| 安吉县| 龙海市| 始兴县| 抚顺市| 沭阳县| 余干县| 南昌市|