Monday, September 25, 2017

Looping Structure - Find Output [17 Programs] SEE Qbasic Practice PART III

1.      DECLARE SUB PATT(A$)
CLS
A$ = “*”
CALL PATT(A$)
END

SUB PATT(A$)
A = 10
FOR I = 1 TO 11 STEP 2
PRINT TAB(A); STRING$(I,A$)
A = A-1
NEXT
END  SUB

2.      DECLARE SUB CHK (N$())
CLS
FOR I= 1 TO 5
READ N$(I)
NEXT I
CALL CHK (N$())
DATA Patan, Pray, Ada, Cabbage, English, Samsung
END

SUB CHK (N$())
FOR I = 1 TO 5
S$=-S$+MID$(N$(I)),I,1)
NEXT I
PRINT S$
END SUB

3.      DECLARE SUB DISPLAY(B$)
CLS
CALL DISPLAY(“101”)
END

SUB DISPLAY(B$)
FOR I=LEN(B$) TO 1 STEP-1
A$=MIS$(B$,I,1)
C=VAL(A$)
D=D+C*8^P
P=P+1
NEXT I
PRINT D
END SUB

4.      DECLARE SUB RESULT (S$)
CLS
A$=”PROGRAMMER”
CALL RESULT (A$)
END

SUB RESULT (A$)
FOR C= LEN (A$) TO 1 STEP -2
X$= MID$(A$, C, 1)
PRINT X$;
C=C-1
NEXT C
END SUB


5.      DECLARE SUB PRO (A AS INTEGER, B AS STRING)
CLS
N = 62
CALL PRO (N, S$)
PRINT S$
END

SUB PRO (A AS INTEGER, B AS STRING)
X = A
DO
R = X MOD 8
B = STR$ (R) + B
X = (X - R) / 8
LOOP UNTIL X = 0
END SUB


6.      DECLARE SUB SHOW (ABC$)
CLS
AB$="ZHTUOMENXSA"
CALL SHOW (AB$)
END

SUB SHOW (AB$)
Y=48
FOR I=1 TO 5
N=Y MOD 7
PRINT MID$(AB$, N, 1);
Y=Y-1
NEXT I
END SUB

7.      DECLARE SUB RESULT ( )
CLS
CALL RESULT
END

SUB RESULT ()
W$="SCIENCE"
L=LEN (W$)
X=1: Y=3
FOR I= 1 TO L STEP 2
PRINT TAB (Y); MID$(W$, X, L)
X=X+1
L=L-2
Y=Y+1
NEXT I
END SUB

8.      DECLARE SUB RESULT(A$)
A$ = "EDUCATION"
CALL RESULT(A$)
END

SUB RESULT (A$)
FOR C = 1 TO LEN(A$) STEP 2
 X$ = MID$(A$, C, 1)
PRINT X$
NEXT C
END SUB

9.      DECLARE SUB RESULT(N$)
N$ = "SCIENCE"
CALL RESULT(N$)
END

SUB RESULT (N$)
B = LEN(N$)
COUNT = 1
WHILE COUNT <= B
 X$ = X$ + MID$(N$, COUNT, 1)
 COUNT = COUNT + 2
WEND
PRINT X$
END SUB

10.   DECLARE SUB TEST(A$)
CLS
A$="NEPAL"
CALL TEST(A$)
END

SUB TEST(A$)
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)  +  B$
NEXT I
PRINT B$
END SUB

11.   DECLARE SUB FIRST()
CLS
CALL FIRST
END

SUB FIRST()
A$=”BHAKTAPUR”
FOR I=1 TO LEN(A$)
B$ = MID$(A$,1,I)
PRINT B$
NEXT I
END SUB

12.   DECLARE  SUB  PICTURE (ST$)
CLS
X$ = "SCIENCE"
CALL PICTURE(ST$)
END

SUB PICTURE(S$)
T=20
P=4
N=1
FOR A= 1 TO 4
PRINT TAB(T); MID$(ST$,P,N)
P=P-1
N=N+2
T=T-1
NEXT A
END SUB


13.   DECLARE SUB EVE (BA$)
CLS
CALL EVE("CHOYU")
END

SUB EVE(BA$)
COL=1
FOR I= LEN(BA$) TO 1 STEP -2
PRINT TAB(COL);MID$(BA$,COL,I)
COL=COL+1
NEXT
END SUB

14.   DECLARE SUB PATTERN (W$)
CLS
LET W$=”KATHMANDU”
CALL PATTERN (N$)
END

SUB PATTERN (N$)
T=5
FOR K=1 TO LEN(W$) STEP 2 
PRINT TAB(T); MID$(W$,T,K)
T=T-1
NEXT K
END SUB

15.   DECLARE SUB TEST(N$)
CLS                                                                                              
A$ = “KATHMANDU”                                                                  
CALL TEST(A$)
CALL TEST(“BHAKTAPUR”)
END

SUB TEST(N$)
FOR C = 1 TO LEN(N$)
PRINT LEFT$ (N$,C)
NEXT C
END SUB



16.   DECLARE SUB PRO (A, B$)
N = 62
INPUT “Enter a word”; S$
CALL PRO (N, S$)
PRINT “End of the Game.”
END

SUB PRO (A , B$)
X = A
DO
R = X MOD 8
B$ = STR$ (R) + B$
X = (X - R) / 8
LOOP UNTIL X = 0
PRINT B$
END SUB


17.   DECLARE SUB PATTERN(S$)
CLS
B$=”PROGRAM”
CALL PATTERN(B$)
END

SUB PATTERN(S$)
H=LEN(S$)
I=10
FOR J=1 TO H STEP 2
PRINT TAB(I); MID$(S$,J,H)
H=H-2
I=I+1
NEXT J
END SUB

1 comment: