- Comprehensive Ruby Programming
- Jordan Hudgens
- 136字
- 2021-07-02 21:13:29
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
推薦閱讀
- Python程序設(shè)計(jì)(第3版)
- OpenCV 3和Qt5計(jì)算機(jī)視覺應(yīng)用開發(fā)
- Java Web程序設(shè)計(jì)
- Silverlight魔幻銀燈
- 老“碼”識(shí)途
- STM32F0實(shí)戰(zhàn):基于HAL庫(kù)開發(fā)
- 深入淺出RxJS
- Visual C#.NET程序設(shè)計(jì)
- JAVA程序設(shè)計(jì)實(shí)驗(yàn)教程
- .NET 3.5編程
- 前端HTML+CSS修煉之道(視頻同步+直播)
- C語言程序設(shè)計(jì)教程
- HTML 5與CSS 3權(quán)威指南(第3版·上冊(cè))
- 利用Python進(jìn)行數(shù)據(jù)分析
- Android開發(fā)三劍客:UML、模式與測(cè)試