Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Atomic-updates/FreeBASIC/atomic-updates.basic
Normal file
38
Task/Atomic-updates/FreeBASIC/atomic-updates.basic
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Randomize Timer
|
||||
Dim Shared As Uinteger cubo(1 To 10), a, i
|
||||
For i As Uinteger = 1 To 10
|
||||
cubo(i) = Int(Rnd * 90)
|
||||
Next i
|
||||
|
||||
Function Display(cadena As String) As Uinteger
|
||||
Dim As Uinteger valor
|
||||
Print cadena; Spc(2);
|
||||
For i As Uinteger = 1 To 10
|
||||
valor += cubo(i)
|
||||
Print Using "###"; cubo(i);
|
||||
Next i
|
||||
Print " Total:"; valor
|
||||
Return valor
|
||||
End Function
|
||||
|
||||
Sub Flatten(f As Uinteger)
|
||||
Dim As Uinteger f1 = Int((f / 10) + .5), f2
|
||||
For i As Uinteger = 1 To 10
|
||||
cubo(i) = f1
|
||||
f2 += f1
|
||||
Next i
|
||||
cubo(10) += f - f2
|
||||
End Sub
|
||||
|
||||
Sub Transfer(a1 As Uinteger, a2 As Uinteger)
|
||||
Dim As Uinteger temp = Int(Rnd * cubo(a1))
|
||||
cubo(a1) -= temp
|
||||
cubo(a2) += temp
|
||||
End Sub
|
||||
|
||||
a = Display(" Display:") ' show original array
|
||||
Flatten(a) ' flatten the array
|
||||
a = Display(" Flatten:") ' show flattened array
|
||||
Transfer(3, 5) ' transfer some amount from 3 to 5
|
||||
Display(" 19 from 3 to 5:") ' show transfer array
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue