Fortran parameter
时间: 2023-10-04 09:09:31 浏览: 59
Fortran语言教程.docx
In Fortran, a parameter is a named constant that is assigned a value that cannot be changed during the execution of the program. It is declared using the `parameter` keyword followed by the name of the constant and its value.
For example, consider the following code:
```
program example
implicit none
integer, parameter :: n = 10
real, parameter :: pi = 3.14159
print *, "The value of n is:", n
print *, "The value of pi is:", pi
end program example
```
In this code, we have declared two parameters `n` and `pi`. The value of `n` is set to 10 and the value of `pi` is set to 3.14159. These values cannot be changed during the execution of the program.
When we run the program, it will print the following output:
```
The value of n is: 10
The value of pi is: 3.14159012
```
Note that parameters are often used to define physical or mathematical constants that are used throughout the program. They can also be used to simplify the code and make it more readable by replacing hard-coded values with named constants.
阅读全文