Clarion C10
Версия реализации Clarion C7+ языка программирования ClarionC10 Gold + was released on November 2015.
C10 was re-worked to build up on .NET 4
Примеры:
Числа Фибоначчи - Clarion (579):
использование 64-битной арифметики
PROGRAM
OMIT('***')
* User: Shur
* Date: 29.02.2016
* Time: 21:18
***
MAP
include('i64.inc')
ShowINT64 PROCEDURE(*INT64 a),STRING
END
a LIKE(INT64)
b LIKE(INT64)
c LIKE(INT64)
str1 CSTRING(32000)
str2 CSTRING(32000)
CODE
a.lo = 1
str1 = '1=' & ShowINT64(a)
b.lo = 1
str1 = str1 & '|2=' & ShowINT64(b)
str2 ='1, 1'
loop i# = 3 to 200
i64Add(a,b,c)
if i64Sign(c) = -1
break
end
a :=: b ! deep assignment uses for structures
b = c ! usual assignment can be also used
str1 = str1 & '|' & i# & '=' & ShowINT64(c)
str2 = str2 & ', ' & ShowINT64(c)
end
message(str2,'Fibonacci',,,,10b)
message(str1,'Fibonacci',,,,10b)
ShowINT64 PROCEDURE(a)
d DECIMAL(30,0)
CODE
i64ToDecimal(d,a)
return(d)
Факториал - Clarion (580):
используется рекурсия. вычисляются 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
]]>