A Simple BASIC Program for String Manipulation R ER TER UTER PUTER MPUTER OMPUTER COMPUTER (String Pattern)

1 year ago

String manipulation is a fundamental aspect of programming, allowing developers to transform and extract information from text data. In this exploration, we'll focus on a captivating string manipulation pattern showcased in a simple BASIC program. Here is the simple string manipulation string pattern printing program. Teh program will print the following pattern. 

R
ER
TER
UTER
PUTER
OPUTER
MPUTER
OMPUTER
COMPUTER

 

Program

CLS
X$ = "COMPUTER"
FOR i = 1 TO LEN(X$)
     PRINT RIGHT$(X$, i)
NEXT i
END

- CLS: Clears the screen
- X$ = "COMPUTER" Here, X$ string variable is declared and assigned the value "COMPUTER"
- FOR i = 1 TO LEN(X$): This initiates a loop that iterates from 1 to the length of the string X$
- PRINT RIGHT$(X$, i): Within the loop, this line prints a substring of X$ starting from the rightmost character and moving leftwards.
- NEXT i: Marks the end of the loop

 

Using SUB PROCEDURE

DECLARE SUB pattern(a$)
CLS
x$ = "COMPUTER"
CALL pattern(x$)
END

SUB pattern (a$)
FOR i = 1 TO LEN(a$)
     PRINT RIGHT$(a$, i)
NEXT i
END SUB

Using FUNCTION Procedure

DECLARE FUNCTION pattern()
CLS
d = pattern
END

FUNCTION pattern
a$ = "COMPUTER"
FOR i = 1 TO LEN(a$)
     PRINT RIGHT$(a$, i)
NEXT i
END FUNCTION

 

 

  761
Please Login to Post a Comment