×
Fortran教程Fortran语言环境设置Fortran基本语法Fortran数据类型Fortran变量Fortran常量Fortran运算符Fortran算术运算符Fortran关系运算符Fortran逻辑运算符Fortran运算符优先级Fortran选择决策Fortran if...then语句结构Fortran if...then...else 结构Fortran if...else if...else 语句Fortran嵌套if结构Fortran select case结构Fortran嵌套select case结构Fortran循环Fortran do循环结构Fortran do...while循环结构Fortran嵌套循环Fortran exit语句Fortran Cycle语句Fortran Stop语句Fortran数字Fortran字符Fortran字符串Fortran数组Fortran向量和矩阵乘法函数Fortran还原功能Fortran查询函数Fortran构造函数Fortran重塑函数Fortran操作函数Fortran位置函数Fortran动态数组Fortran导出数据类型Fortran指针Fortran基本输入输出Fortran文件输入输出Fortran过程Fortran模块Fortran内部函数Fortran数字精度Fortran编程风格Fortran调试程序

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

分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)