Site icon Pathshala Nepal

Write a program to print string pattern. NEPAL, NEPA, NEP, NE, N

Q BAISC OS
Online Calculator

Write a program to print following string pattern.

NEPAL
NEPA
NEP
NE
N


1 Answer


CLS

A$ = "NEPAL"

FOR I = LEN(A$) TO 1 STEP -1

B$ = LEFT$ (A$,1)

PRINT B$

NEXT I

END

 

FOLLOWING ARE THE IMPORTANT POINTS WE NEED TO REMEMBER IN PATTERNS:

  1. To start with string patterns, first we see which side has the similar patterns or characters. Like for pattern a, the letter 'N' is same on the left hand side whereas for pattern b) the letter 'L' is same on the right hand side. So we use LEFT$ for the pattern a and RIGHT$ for pattern b.
  2. Second, the patterns have to be printed using loop. The value of loop is determined by the number of character they have at the top. Like, for pattern a, the number of characters are 5 which is length of the string and in pattern c, it starts with 'N' which is 1.
  3. So for pattern a, we start the loop with LEN and the final value will be 1 and for pattern c we start the loop with 1 and the final value will be LEN.
  4. When we start loop with LEN, the step must be negative.
Topics from Computer
Related Questions