To generate the given pattern C CO COM COMP COMPU COMPUT COMPUTE COMPUTER (Qbasic Code)

To generate the given pattern
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER

  • CLS
    LET a$ = "COMPUTER"
    FOR i = 1 TO LEN(a$)
        PRINT LEFT$(a$, i)
    NEXT i
    END

Using SUB Procedure
DECLARE SUB pattern (a$)
CLS
CALL pattern(a$)
END

SUB pattern (a$)
LET a$ = "COMPUTER"
FOR i = 1 TO LEN(a$)
    PRINT LEFT$(a$, i)
NEXT i
END SUB


Using FUNCTION Procedure
  • Without parameters
  • DECLARE FUNCTION pattern ( )
    CLS
    p = pattern
    END
    FUNCTION pattern
    a$ = "COMPUTER"
    FOR i = 1 TO LEN(a$)
        PRINT LEFT$(a$, i)
    NEXT i
    END FUNCTION
  • With parameters
  • DECLARE FUNCTION pattern$(a$)
    CLS
    p$ = pattern$(a$)
    END
    FUNCTION pattern$ (a$)
    a$ = "COMPUTER"
    FOR i = 1 TO LEN(a$)
        PRINT LEFT$(a$, i)
    NEXT i
    END FUNCTION

Share :

Twitter
Back To Top

facebook main

counter

Powered by Blogger.