Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
44
Task/Catamorphism/FreeBASIC/catamorphism.freebasic
Normal file
44
Task/Catamorphism/FreeBASIC/catamorphism.freebasic
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Type IntFunc As Function(As Integer, As Integer) As Integer
|
||||
|
||||
Function reduce(a() As Integer, f As IntFunc) As Integer
|
||||
'' if array is empty or function pointer is null, return 0 say
|
||||
If UBound(a) = -1 OrElse f = 0 Then Return 0
|
||||
Dim result As Integer = a(LBound(a))
|
||||
For i As Integer = LBound(a) + 1 To UBound(a)
|
||||
result = f(result, a(i))
|
||||
Next
|
||||
Return result
|
||||
End Function
|
||||
|
||||
Function add(x As Integer, y As Integer) As Integer
|
||||
Return x + y
|
||||
End Function
|
||||
|
||||
Function subtract(x As Integer, y As Integer) As Integer
|
||||
Return x - y
|
||||
End Function
|
||||
|
||||
Function multiply(x As Integer, y As Integer) As Integer
|
||||
Return x * y
|
||||
End Function
|
||||
|
||||
Function max(x As Integer, y As Integer) As Integer
|
||||
Return IIf(x > y, x, y)
|
||||
End Function
|
||||
|
||||
Function min(x As Integer, y As Integer) As Integer
|
||||
Return IIf(x < y, x, y)
|
||||
End Function
|
||||
|
||||
Dim a(4) As Integer = {1, 2, 3, 4, 5}
|
||||
Print "Sum is :"; reduce(a(), @add)
|
||||
Print "Difference is :"; reduce(a(), @subtract)
|
||||
Print "Product is :"; reduce(a(), @multiply)
|
||||
Print "Maximum is :"; reduce(a(), @max)
|
||||
Print "Minimum is :"; reduce(a(), @min)
|
||||
Print "No op is :"; reduce(a(), 0)
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue