BasicsTutorial/Arithmetic Operators

Last-modified: 2009-11-28 (土) 21:16:49

Arithmetic Operators

算術演算子

Now what about maths?
現在、数学はどう?
That’s another big part of programming and there are a set of ‘Arithmetic Operators’ to deal with maths.
それはプログラミングのもう一つの大きい部分である、そして、一組の『算術演算子』が数学に対処するためにある。
Here they are…
ここ、それがare…である

+ : addition operator
+:加算演算子
- : subtraction operator
-:引き算演算子
* : multiplication operator
*:掛け算演算子
/ : division operator
/:割り算演算子
^ : power operator
^:乗算演算子
MOD : modulation operator
MOD:あまり演算子

具体的に

And here is how they work.
そして、ここでは、それが働く方法である。
Basically, put an operator between 2 numbers and you get the result of the two numbers ‘operated’.
基本的に、二つの数字の間で演算子(オペレーター)を配置しなさい、そして、あなたは二つの数字の結果を『演算』てもらう。
For example 2+5 is equal to 7, so…
たとえば、2+5は 7と等しい、so…

Print 2+5
Wait key

Will result in 7 being printed on the screen.
スクリーンにプリントされて、結果が 7

7-3 is equal to 4, so do…
7-3は、 4と等しい、それで、do…

Print 7-3
Wait key

And you will get 4 being printed on the screen.
そして、あなたは 4をスクリーンにプリントされるようにする。
 * multiplies numbers together, / divides them, ^ finds the first number to the power of the second number (eg. 2^5 is equal to 2*2*2*2*2 is equal to 32), and the last operator MOD will find the remainder when the two numbers are divided, for example 9 MOD 4 equals 2 remainder 1, so 9 MOD 4 will equal 1.
 *はかけ算、 /は割り算、 ^乗算、 最初のものを第2の数だけ掛け算する(例えば。2^5は、2*2*2*2*2と等しい32と等しくある)、 MODは 二つの数を割り算された残りの数、たとえば、9MOD4は 2余り1に等しいので、9MOD4は1に等しい。
8 MOD 4 will equal 0 and 11 MOD 4 will equal 3.
8MOD4は 0に等しい、そして、11MOD4は3に等しい。
The MOD operator is not used as much as the others (in fact, I’ve never used it or seen it used in any practical situation, but I’m sure it has some use).
MODの演算子が、他(実際、私はこれまでそれを使わなかったか、それが少しの実際的な状況でも使われるのを見なかった、しかし、私はそれがいくらかの使用をすると確信する)ほどあまり、使われない。

You can use arithmetic operators wherever you use numbers or variables, e.g.
どこで、例えば、あなたが数または変数を使っても、あなたは算術演算子を使うことができる。

`Get users numbers
Input "Choose a number: ",numOne#
Input "Choose another Number: ",numTwo#
`Work out numbers
added# = numOne# + numTwo#
subtracted# = numOne# - numTwo#
multiplied# = numOne# * numTwo#
divided# = numOne# / numTwo#
power# = numOne# ^ numTwo#
`Print mathematical stuff
Print numOne#," + ",numTwo#," = ",added#
Print numOne#," - ",numTwo#," = ",subtracted#
Print numOne#," * ",numTwo#," = ",multiplied#
Print numOne#," / ",numTwo#," = ",divided#
Print numOne#," to the power of ",numTwo#," = ",power#
Wait key

In this code we store the two numbers given by the user in different variables.
このコードでは、我々は 異なる変数でユーザーによって与えられる二つの数字を保存する。
Remember, you can use variables wherever numbers are used, including with arithmetic operators.
思い出しなさい。数が算術演算子で使われるどこにでも、あなたは変数を使うことができる。
We then print them.
我々は、それからそれらをプリントする。
We use variables to store the new values as it is easier to look at and edit than if we had stuck it all in the PRINT line like this.
我々がこのようにそれのすべてをPRINT行に入れたよりそれが見て、編集するのがより簡単で、我々は新しい値を保存するために変数を使う。

Print numOne#," to the power of ",numTwo#," = ", numOne# ^ numTwo#

You can also combine many numbers and arithmetic operators to get complicated sequences.
あなたは、複雑なシーケンスを得るために、多くの数と算術演算子を結合することもできる。

complex# = 3 * (4 + 2) / 10.0^2 - 7 + 1

In this sum there are many operators and numbers and some brackets.
この合計において、多くの演算子と数と若干の括弧が、ある。
DBPro follows the BODMAS rule, that is:
つまり、DBProはBODMAS規則に続く:

Brackets
括弧()

Of (to the power Of)
乗算

Division
割り算

Multiplication
掛け算

Addition
加算

Subtraction
引き算

So brackets are calculated first.
それで、括弧は最初に計算される。
Any sums inside the brackets follow the BODMAS rule again, but in this case there is only one operator, the addition operator, so there is no BODMAS involved.
括弧の内側のどんな合計でも再びBODMAS支配に続く、しかし、この場合、1つのオペレーター(追加演算子)だけがあるので、関係するBODMASがない。

complex# = 3 * 6 / 10.0^2 - 7 + 1

Then powers.
そして掛け算。

complex# = 3 * 6 / 100.0 - 7 + 1

Then division.
そして割り算。

complex# = 3 * 0.06 - 7 + 1

Then multiplication.
そして掛け算。

complex# = 0.18 - 7 + 1

Then the subtractiuon and addition are done in the order they are written in code.
それから、引き算と足し算は、それがコードで書かれる順番でされる。
In this case, subtraction first.
この場合、最初に引き算。

complex# = -6.82 + 1

The finally addition.
最後に足し算。

complex# = -5.82

注意書き

Notice how I used 6 / 100.0, that is because if I had left off the decimal point, the answer would have been an integer,
どのように私が 6 / 100.0を使ったか気付く、それが もし私が少数点を使わないでおいていたなら、答えが整数であったであろうからである、

you need to write your numbers as floats to get float answers, this only really counts for division since that is the only operator where operating 2 integers can result in a float
手に入れるべき 答えがフローとであるから、あなたは 数をフロートで書く必要がある、それが演算上の2つの整数がフロートをもたらすことができる唯一のやり手であるので、これはただ本当に割り算に あてはまるだけである、

(add 2 integers = integer, subtract 2 integers = integer, multiply 2 integers = integer, power an integer = integer).
(2整数の加算=整数、2整数の引き算=整数、2整数の掛け算=整数、整数の乗算=整数 となる)

Anyway, I think that’s enough on these type of operators, onto the next type.
とにかく、次のタイプの上へ、私はそれでこれらの種類の演算子の上で十分であると思う。

訳者補足

演算順序は正確には以下である


( )
^
+-(符号), NOT
* /
+ -(加算 減算)
<  <=  <>  =  >  >=
AND OR

同列の場合は、前から順番に、わかりづらい時は 括弧を使って強制的に優先順位をつける事

End of Section Tasks

セクション終わりの作業

l Ask the user for 2 numbers to add, 2 to subtract, 2 to multiply, 2 to divide and 2 to modulate.

  • 二つの数字を 加える、引く2、増える2、割り算れる2と2のためのユーザーにあまるするよう頼みなさい。
    Then write all the answers.
    それから、全ての答えを書きなさい。

l Print the multiplication table for any number that is entered from 1 to 10.

  • 1から10まで入れられるどんな数のためにでも、乗算表をプリントしなさい。

l Print the square and cube numbers from 1 to 10

  • 1から10まで正方形と立方体番号をプリントしなさい