Advertisement
Oppaceted

Задание 1

Feb 16th, 2023
484
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 (*,'(1x,a$)') 'Enter n:'
  11.         read (*,*) n
  12.         if (n >= 20 .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.     write (*,'(1x,a f20.5)') 'Factorial n:', fact(n)
  21. end program
  22. real(8) function fact(r)
  23.     real(8), parameter :: pi = 3.141592653589793, e = 2.718281828459045
  24.     real(8):: ratio(5)
  25.     real :: multi_1, multi_2
  26.     integer :: r,i
  27.     ratio = [1.0, (1.0/12.0), (1.0/288.0), (-139.0/51480.0), (-571.0/2488320.0)]
  28.     !
  29.     fact = 0.000000
  30.     if (r == 0) then
  31.         fact = 1.00000000
  32.     else
  33.         do i = 1, size(ratio)
  34.             fact = fact + ratio(i)/(r**(i-1))
  35.         end do
  36.         fact = fact*sqrt(2*pi*r)*( (r/e)**r )
  37.     end if
  38.     !multi_2 = ratio_1 + (ratio_2/r) + (ratio_3/(r**2)) + (ratio_4/(r**3)) + (ratio_5/(r**4))
  39.     !fact = multi_1*multi_2
  40. end function
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement