How to declare real constants in Fortran? Please help

In summary, to declare real constants in Fortran, you can use the "parameter" keyword followed by the variable name and the value assigned to it. You can also declare multiple real constants in one line by separating each constant with a comma. To specify a specific precision for a real constant, you can use the "kind" keyword. There is no specific order in which real constants need to be declared, as long as the "parameter" keyword is used. Once declared, real constants cannot be changed in Fortran and a new variable must be declared if a different value is needed.
  • #1
onlybarca6
5
0
How do I declare constants beginning with "zero" in Fortran to get the output beginning with zero ?

If I declare :

REAL, parameter :: tension = 0.025

I get the output:

2.500000E-02



Thanks in advance
 
Technology news on Phys.org
  • #2
I think you want to look at FORMAT descriptors.
 

1. How do I declare real constants in Fortran?

To declare a real constant in Fortran, you can use the "parameter" keyword followed by the variable name and the value assigned to it. For example:
parameter :: pi = 3.14159
This will declare a real constant named "pi" with the value of 3.14159.

2. Can I declare multiple real constants in one line in Fortran?

Yes, you can declare multiple real constants in one line by separating each constant with a comma. For example:
parameter :: a = 5.0, b = 10.0, c = 15.0
This will declare three real constants named "a", "b", and "c" with the values of 5.0, 10.0, and 15.0 respectively.

3. How can I declare real constants with a specific precision in Fortran?

You can use the "kind" keyword followed by the desired precision value after the equal sign when declaring a real constant. For example:
parameter :: pi = 3.14159_kind(8)
This will declare a real constant named "pi" with a precision of 8 digits after the decimal point.

4. Is it necessary to declare real constants in a specific order in Fortran?

No, it is not necessary to declare real constants in a specific order in Fortran. You can declare them in any order you want, as long as you use the "parameter" keyword before each declaration.

5. Can I change the value of a declared real constant in Fortran?

No, a declared real constant cannot be changed in Fortran. It is a fixed value that remains constant throughout the program execution. If you need to change the value, you can declare a new real variable and assign a different value to it.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
941
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
8
Views
850
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
Back
Top