]]> ]]>

Факториал в Clarion

Пример для версий Clarion C10

используется рекурсия. вычисляются 20 членов ряда.

1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 7! = 5040 8! = 40320 9! = 362880 10! = 3628800 11! = 39916800 12! = 479001600 13! = 6227020800 14! = 87178291200 15! = 1307674368000 16! = 20922789888000 17! = 355687428096000 18! = 6402373705728000 19! = 121645100408832000 20! = 2432902008176640000

  PROGRAM

OMIT('***')
 * User: Shur
 * Date: 29.02.2016
 * Time: 23:49
 ***

  MAP
      include('i64.inc')
Factorial PROCEDURE(SHORT,*INT64 a)
ShowINT64  PROCEDURE(*INT64 a),STRING
  END

a                    LIKE(INT64)
b                    LIKE(INT64)
c                    LIKE(INT64)
str1                 CSTRING(32000)
str2                 CSTRING(32000)

   CODE       
      Factorial(20,a)
      message(str1,'Factorial',,,,10b)

Factorial            PROCEDURE(SHORT n,*INT64 a)
b like(INT64)
   CODE
      if n = 1 then
         i64Assign(a,1)
         str1 = '1! = 1'
         RETURN
      .
      i64Assign(b,n)     
      Factorial(n-1,a)
      if a.lo = 0 and a.hi = 0
         RETURN
      .   
      i64Mult(a,b,c)
      if i64Sign(c) = -1 
         i64Assign(a,0)
         RETURN
      .   
      a :=: c
      str1 = str1 & '|' & n & '! = ' & ShowINT64(a)
      
ShowINT64           PROCEDURE(a)
d DECIMAL(30,0)
   CODE
      i64ToDecimal(d,a)
      return(d)

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам