How to resolve the algorithm Apply a callback to an array step by step in the FreeBASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Apply a callback to an array step by step in the FreeBASIC programming language

Table of Contents

Problem Statement

Take a combined set of elements and apply a function to each element.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Apply a callback to an array step by step in the FreeBASIC programming language

Source code in the freebasic programming language

' FB 1.05.0 Win64

Sub PrintEx(n As Integer)
  Print n, n * n, n * n * n
End Sub

Sub Proc(a() As Integer, callback As Sub(n As Integer))
  For i As Integer = LBound(a) To UBound(a)
    callback(i)
  Next
End Sub

Dim a(1 To 10) As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Print " n", "n^2", "n^3"
Print " -", "---", "---"
Proc(a(), @PrintEx)
Print
Print "Press any key to quit the program"
Sleep

  

You may also check:How to resolve the algorithm Pan base non-primes step by step in the Java programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the Erlang programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the Fortran programming language
You may also check:How to resolve the algorithm Create a file step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Chinese zodiac step by step in the ALGOL 68 programming language