while loop - Given value p, return last element of sequence < p - Fortran -
i have sequence of numbers follows:
1 , 1, 5, 13, 41, 121, 365, ....
the first 2 values are:
n(1) = 1 , n(2) = 1
as 3rd value, n(i) = 2*n(i-1) + 3*n(i-2)
the issue facing is: if give argument of p, should return me last values of sequence < p (using fortran77).
for instance, if p = 90, should return value 41.
a = 1 b = 1 while b < p: c = 2 * b + 3 * = b b = c return
the fortran equivalent is:
function fct(p) result(a) integer, intent(in) :: p integer :: a, b, c = 1 b = 1 while (b < p) c = 2 * b + 3 * = b b = c enddo end function program test integer :: fct external fct print *,fct(90) end program
Comments
Post a Comment