- 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
推薦閱讀
- JavaScript:Functional Programming for JavaScript Developers
- Interactive Data Visualization with Python
- Software Testing using Visual Studio 2012
- Java程序設計與計算思維
- Web程序設計(第二版)
- Nexus規模化Scrum框架
- 精通Python自然語言處理
- Hands-On Functional Programming with TypeScript
- 微信小程序開發與實戰(微課版)
- Mobile Device Exploitation Cookbook
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- Head First Kotlin程序設計
- R語言數據分析從入門到實戰
- 深入理解C++11:C++11新特性解析與應用
- Responsive Web Design with HTML5 and CSS3(Second Edition)