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

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
主站蜘蛛池模板: 库尔勒市| 太白县| 红桥区| 和政县| 和政县| 衡东县| 同德县| 瑞金市| 小金县| 托里县| 贡嘎县| 郴州市| 诸城市| 丰镇市| 苏尼特右旗| 上杭县| 温州市| 嘉荫县| 藁城市| 黄大仙区| 西城区| 甘孜县| 土默特右旗| 珠海市| 南康市| 渭源县| 宝丰县| 华池县| 和田县| 长垣县| 应城市| 美姑县| 曲阳县| 隆回县| 五华县| 庆安县| 商水县| 高要市| 尤溪县| 东安县| 望都县|