• Courses
• Data Structure
• ### QBASIC Program to print string pattern a, BB, ccc, DDDD, eeeee, FFFFFF

Posted on 2021-01-27

QBAIC String pattern printing program a, BB, ccc, DDDD, eeeee, ffffff. There can be more then one solution or code to print this kind of patterns in qbasic. It will be better to use LCASE\$ and UCASE\$ library functions with IF .. ELSE Statement. We will put the string 'abcdef' in a string variable s\$ and we will go through for loop with MID\$ function to read each character. If the loop is even then we will print the latter in capital letter otherwise in small letter.

Simple Program

``````CLS
s\$ = "abcdef"
FOR i = 1 TO LEN(s\$)
FOR j = 1 TO i
l\$ = MID\$(s\$, i, 1)
IF i MOD 2 = 0 THEN
PRINT UCASE\$(l\$);
ELSE
PRINT LCASE\$(l\$);
END IF
NEXT j
PRINT
NEXT i
END
``````

OUTPUT

```a
BB
ccc
DDDD
eeeee
FFFFFF```

Using SUB ... END SUB

``````DECLARE SUB Pat(s\$)
CLS
s\$ = "abcdef"
CALL Pat(s\$)
END

SUB Pat (s\$)
FOR i = 1 TO LEN(s\$)
FOR j = 1 TO i
l\$ = MID\$(s\$, i, 1)
IF i MOD 2 = 0 THEN
PRINT UCASE\$(l\$);
ELSE
PRINT LCASE\$(l\$);
END IF
NEXT j
PRINT
NEXT i
END SUB

``````

Using FUNCTION ... END

``````
DECLARE FUNCTION Pat(s\$)
CLS
s\$ = "abcdef"
c = Pat(s\$)
END

FUNCTION Pat (s\$)
FOR i = 1 TO LEN(s\$)
FOR j = 1 TO i
l\$ = MID\$(s\$, i, 1)
IF i MOD 2 = 0 THEN
PRINT UCASE\$(l\$);
ELSE
PRINT LCASE\$(l\$);
END IF
NEXT j
PRINT
NEXT i
END FUNCTION
``````

544

#### Recent MCQs

 MS-Excel Quick Tip 2 MS-Excel Quick Tip 1 MS-Word Quick Tip 3 MS-Word Quick Tip 2