Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ! Вариант 3/93 в Шелесте
- program hello
- implicit none
- integer :: n
- real(8) :: fact
- do while (.true.)
- write (*,'(a$)') 'Enter n:'
- read (*,*) n
- if (n >= 100 .or. n <=0 ) then
- write (*,*) 'Incorrect enter!'
- cycle
- else
- exit
- end if
- end do
- write (*,*) 'Factorial n:', fact(n)
- end program
- real(8) function fact(r)
- real(8), parameter :: pi = 3.141592653589793, e = 2.718281828459045
- !real(8), parameter :: ratio_1 = 1.0, ratio_2 = (1.0/12.0), ratio_3 = (1.0/288.0)!
- !real(8), parameter :: ratio_4 = (-139.0/51480.0), ratio_5 = (-571.0/2488320.0) !коэффициенты степенного ряда
- real(8):: ratio(5)
- real :: multi_1, multi_2
- integer :: r,i
- ratio = [1.0, (1.0/12.0), (1.0/288.0), (-139.0/51480.0), (-571.0/2488320.0)]
- !
- fact = 0.000000
- do i = 1, size(ratio)
- fact = fact + ratio(i)/(r**(i-1))
- end do
- fact = fact*sqrt(2*pi*r)*( (r/e)**r )
- !multi_2 = ratio_1 + (ratio_2/r) + (ratio_3/(r**2)) + (ratio_4/(r**3)) + (ratio_5/(r**4))
- !fact = multi_1*multi_2
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement