Fortran-arithmetic-operators

提供:Dev Guides
移動先:案内検索

Fortran-算術演算子

次の表は、Fortranでサポートされているすべての算術演算子を示しています。 変数 A が5を保持し、変数 B が3を保持すると仮定します-

Operator Description Example
+ Addition Operator, adds two operands. A + B will give 8
- Subtraction Operator, subtracts second operand from the first. A - B will give 2
* Multiplication Operator, multiplies both operands. A* B will give 15
/ Division Operator, divides numerator by de-numerator. A/B will give 1
* * Exponentiation Operator, raises one operand to the power of the other. A* *B will give 125

Fortranで利用可能なすべての算術演算子を理解するために、次の例を試してください-

program arithmeticOp

! this program performs arithmetic calculation
implicit none

   ! variable declaration
   integer :: a, b, c

   ! assigning values
   a = 5
   b = 3

   ! Exponentiation
   c = a*  *b

   ! output
   print* , "c = ", c

   ! Multiplication
   c = a *b

   ! output
   print* , "c = ", c

   ! Division
   c = a/b

   ! output
   print *, "c = ", c

   ! Addition
   c = a + b

   ! output
   print *, "c = ", c

   ! Subtraction
   c = a - b

   ! output
   print *, "c = ", c

end program arithmeticOp

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

c = 125
c = 15
c = 1
c = 8
c = 2