Advertisement
Oppaceted

Untitled

Feb 11th, 2023
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! Вариант 3/93 в Шелесте
  2.  
  3.  
  4.  
  5. program hello
  6.     implicit none
  7.     integer :: n
  8.     real(8) :: fact
  9.     do while (.true.)
  10.         write (*,'(a$)') 'Enter n:'
  11.         read (*,*) n
  12.         if (n >= 100 .or. n <=0 ) then
  13.             write (*,*) 'Incorrect enter!'
  14.             cycle
  15.         else
  16.             exit
  17.         end if
  18.     end do
  19.     write (*,*) 'Factorial n:', fact(n)
  20. end program
  21. real(8) function fact(r)
  22.     real(8), parameter :: pi = 3.141592653589793, e = 2.718281828459045
  23.     !real(8), parameter :: ratio_1 = 1.0, ratio_2 = (1.0/12.0), ratio_3 = (1.0/288.0)!
  24.     !real(8), parameter :: ratio_4 = (-139.0/51480.0), ratio_5 = (-571.0/2488320.0) !коэффициенты степенного ряда
  25.     real(8):: ratio(5)
  26.     real :: multi_1, multi_2
  27.     integer :: r,i
  28.     ratio = [1.0, (1.0/12.0), (1.0/288.0), (-139.0/51480.0), (-571.0/2488320.0)]
  29.     !
  30.     fact = 0.000000
  31.     do i = 1, size(ratio)
  32.         fact = fact + ratio(i)/(r**(i-1))
  33.     end do
  34.     fact = fact*sqrt(2*pi*r)*( (r/e)**r )
  35.     !multi_2 = ratio_1 + (ratio_2/r) + (ratio_3/(r**2)) + (ratio_4/(r**3)) + (ratio_5/(r**4))
  36.     !fact = multi_1*multi_2
  37. end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement