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