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

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
主站蜘蛛池模板: 安泽县| 沂源县| 沧州市| 通渭县| 台南县| 望都县| 托克逊县| 虎林市| 盘山县| 四子王旗| 香河县| 绵阳市| 慈利县| 蛟河市| 临夏市| 仙居县| 尼木县| 郯城县| 平遥县| 波密县| 乐安县| 黔东| 贵阳市| 土默特右旗| 紫云| 静安区| 乐山市| 兰坪| 威信县| 静海县| 宣城市| 洪江市| 上饶市| 瑞金市| 谷城县| 惠来县| 衡东县| 黄石市| 淮滨县| 西华县| 大余县|