Remove duplicates (Only numbers)

General FreeBASIC programming questions.
lrcvs
Posts: 576
Joined: Mar 06, 2008 19:27
Location: Spain

Remove duplicates (Only numbers)

Postby lrcvs » May 02, 2020 9:42

'Experiment # 1: Remove duplicates
'In this experiment, we only use an array
'ONLY NUMBERS!!!


Code: Select all

DECLARE SUB remove_duplicates(d() AS STRING)

DIM AS INTEGER n,x
RANDOMIZE ,3
x = 999
DIM d(x+1) AS STRING
FOR n = 1 TO x+1
    d(n) = LTRIM(STR(INT(RND*2000)))
    'print d(n);" "; 'show numbers
NEXT n
PRINT
PRINT "::::::::::::::::::::::::::::::::::::"

remove_duplicates (d())

FOR n = 0 TO UBOUND(d)
    IF d(n) <> "" THEN PRINT d(n)
NEXT n
SLEEP
END

SUB remove_duplicates(d() AS STRING)
    DIM AS INTEGER j,k
    FOR j = 1 TO UBOUND(d)
        IF d(j) <> "" THEN
            FOR k = j+1 TO UBOUND(d)
                IF d(k)= d(j) THEN d(k) = ""
            NEXT k
        END IF
    NEXT j
END SUB

Return to “General”

Who is online

Users browsing this forum: No registered users and 7 guests