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

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
主站蜘蛛池模板: 武清区| 宁蒗| 健康| 涿州市| 陕西省| 延津县| 株洲县| 彰化市| 蒙阴县| 三穗县| 西乡县| 宁武县| 沾化县| 神农架林区| 英超| 沁水县| 铁岭市| 芜湖市| 沙洋县| 鹤峰县| 兴安县| 浦城县| 新密市| 安仁县| 洛阳市| 稷山县| 同德县| 丰都县| 涡阳县| 汾阳市| 永善县| 新昌县| 彩票| 鄂州市| 凌源市| 连平县| 吴川市| 高阳县| 独山县| 牙克石市| 巴青县|