Fortran算術運算符
下表列出了所有Fortran語言支持的算術運算符。假設變量A=5和變量B=3則:
運算符 | 描述 | 例子 |
---|---|---|
+ | 相加運算符,相加兩個操作數。 | A + B = 8 |
- | 減法運算,第一操作數減去第二操作數。 | A - B = 2 |
* | 乘法運算符,乘兩個操作數。 | A * B = 15 |
/ | 除法運算符,通過分子除以分母。 | A / B = 1 |
** | 乘方運算,一個操作數的B次冪。 | A ** B = 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