In Fortran, you can use the LOG function to calculate the natural logarithm (base e) of a number.
Here’s the basic syntax:
result = LOG(x)
Fortran provides additional functions for logarithms with different bases.
For example, you can use LOG10 to calculate the logarithm with base 10, or LOG2 to calculate the logarithm with base 2.
result10 = LOG10(x)
result2 = LOG2(x)
Example of Usage ‘LOG’ in Fortran:
The following program prompts the user to enter a number, and calculates the natural logarithm using the LOG function, and then prints the result.
program logarithm_example
implicit none
real :: x, result
! Read the input number
write(*,*) "Enter a number:"
read(*,*) x
! Calculate the natural logarithm
result = LOG(x)
! Print the result
write(*,*) "The natural logarithm of", x, "is", result
end program logarithm_example