To print a string in diminishing pattern (Qbasic Code)


Diminishing pattern: that each line is a character less than its previous till a single character is printed in the last line.



REM prints diminishing pattern from string

Using For .... Next Statement

CLS

INPUT "Enter a string"; s$

l = LEN(s$)

FOR i = l TO 1 STEP -1

        PRINT LEFT$(s$, i)

NEXT i

END

END



Using While .. Wend Loop

CLS

INPUT "Enter a string"; s$

l = LEN(s$)

WHILE l > 0

PRINT LEFT$(s$, l)

l = l - 1

WEND

END

Share :

Facebook Twitter
Back To Top

facebook

Powered by Blogger.