51 lines
1.0 KiB
Plaintext
51 lines
1.0 KiB
Plaintext
local fn PopulateArrayWithRandomNumbers
|
|
NSUInteger i
|
|
|
|
for i = 0 to 9
|
|
mda (i) = rnd(90)
|
|
next
|
|
end fn
|
|
|
|
local fn Display( title as CFStringRef ) as NSUInteger
|
|
NSUInteger i, worth = 0
|
|
CFStringRef comma = @","
|
|
|
|
printf @"%@ [\b", title
|
|
for i = 0 to 9
|
|
worth += mda_integer (i)
|
|
if i == 9 then comma = @""
|
|
printf @"%2lu%@\b", mda_integer (i), comma
|
|
next
|
|
printf @"] Sum = %lu", worth
|
|
end fn = worth
|
|
|
|
local fn Flatten( f as NSUInteger )
|
|
NSUInteger i, f1 = int((f / 10) + .5 ), f2 = 0, temp
|
|
|
|
for i = 0 to 9
|
|
mda (i) = f1
|
|
f2 += f1
|
|
next
|
|
temp = mda_integer (9)
|
|
mda (9) = temp + f - f2
|
|
end fn
|
|
|
|
local fn Transfer( a1 as NSUInteger, a2 as NSUInteger )
|
|
NSUInteger t, temp = int( rnd( mda_integer ( a1 ) ) )
|
|
|
|
t = mda_integer ( a1 ) : mda ( a1 ) = t -temp
|
|
t = mda_integer ( a2 ) : mda ( a2 ) = t +temp
|
|
end fn
|
|
|
|
NSUInteger a, i
|
|
|
|
random
|
|
fn PopulateArrayWithRandomNumbers
|
|
a = fn Display( @" Initial array:" )
|
|
fn Flatten( a )
|
|
a = fn Display( @" Current values:" )
|
|
fn Transfer( 3, 5 )
|
|
fn Display( @" 19 from 3 to 5:" )
|
|
|
|
HandleEvents
|