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
82
Task/Arrays/FreeBASIC/arrays.freebasic
Normal file
82
Task/Arrays/FreeBASIC/arrays.freebasic
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
' compile with: FBC -s console.
|
||||
' compile with: FBC -s console -exx to have boundary checks.
|
||||
|
||||
Dim As Integer a(5) ' from s(0) to s(5)
|
||||
Dim As Integer num = 1
|
||||
Dim As String s(-num To num) ' s1(-1), s1(0) and s1(1)
|
||||
|
||||
Static As UByte c(5) ' create a array with 6 elements (0 to 5)
|
||||
|
||||
'dimension array and initializing it with Data
|
||||
Dim d(1 To 2, 1 To 5) As Integer => {{1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}}
|
||||
Print " The first dimension has a lower bound of"; LBound(d);_
|
||||
" and a upper bound of"; UBound(d)
|
||||
Print " The second dimension has a lower bound of"; LBound(d,2);_
|
||||
" and a upper bound of"; UBound(d,2)
|
||||
Print : Print
|
||||
|
||||
Dim Shared As UByte u(0 To 3) ' make a shared array of UByte with 4 elements
|
||||
|
||||
Dim As UInteger pow() ' make a variable length array
|
||||
' you must Dim the array before you can use ReDim
|
||||
ReDim pow(num) ' pow now has 1 element
|
||||
pow(num) = 10 ' lets fill it with 10 and print it
|
||||
Print " The value of pow(num) = "; pow(num)
|
||||
|
||||
ReDim pow(10) ' make pow a 10 element array
|
||||
Print
|
||||
Print " Pow now has"; UBound(pow) - LBound(pow) +1; " elements"
|
||||
' the value of pow(num) is gone now
|
||||
Print " The value of pow(num) = "; pow(num); ", should be 0"
|
||||
|
||||
Print
|
||||
For i As Integer = LBound(pow) To UBound(pow)
|
||||
pow(i) = i * i
|
||||
Print pow(i),
|
||||
Next
|
||||
Print:Print
|
||||
|
||||
ReDim Preserve pow(3 To 7)
|
||||
' the first five elements will be preserved, not elements 3 to 7
|
||||
Print
|
||||
Print " The lower bound is now"; LBound(pow);_
|
||||
" and the upper bound is"; UBound(pow)
|
||||
Print " Pow now has"; UBound(pow) - LBound(pow) +1; " elements"
|
||||
Print
|
||||
For i As Integer = LBound(pow) To UBound(pow)
|
||||
Print pow(i),
|
||||
Next
|
||||
Print : Print
|
||||
|
||||
'erase the variable length array
|
||||
Erase pow
|
||||
Print " The lower bound is now"; LBound(pow);_
|
||||
" and the upper bound is "; UBound(pow)
|
||||
Print " If the lower bound is 0 and the upper bound is -1 it means,"
|
||||
Print " that the array has no elements, it's completely removed"
|
||||
Print : Print
|
||||
|
||||
'erase the fixed length array
|
||||
Print " Display the contents of the array d"
|
||||
For i As Integer = 1 To 2 : For j As Integer = 1 To 5
|
||||
Print d(i,j);" ";
|
||||
Next : Next : Print : Print
|
||||
|
||||
Erase d
|
||||
Print " We have erased array d"
|
||||
Print " The first dimension has a lower bound of"; LBound(d);_
|
||||
" and a upper bound of"; UBound(d)
|
||||
Print " The second dimension has a lower bound of"; LBound(d,2);_
|
||||
" and a upper bound of"; UBound(d,2)
|
||||
Print
|
||||
For i As Integer = 1 To 2 : For j As Integer = 1 To 5
|
||||
Print d(i,j);" ";
|
||||
Next : Next
|
||||
Print
|
||||
Print " The elements self are left untouched but there content is set to 0"
|
||||
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue