Monday, September 25, 2017

Looping Structure - Find Output [30 Programs] SEE Qbasic Practice PART IV

1.      DECLARE FUNCTION OUTP$(A$())
DIM A$(S)
FOR I=1  TO 5
READ A$(I)
NEXT I
DATA NETRA, NAVIN, SUSAN, GOPAL, SUNIL
PRINT OUTP$(A$())
END
FUNCTION OUTP$(A$())
SWAP A$(1),A$(2)
SWAP A$(3),A$(4)
FOR J=1 TO 5
T$=T$+MID$(A$(J),J,1)
NEXT J
OUTP$=T$
END FUNCTION

2.      DECLARE FUNCTION RE$(ST$())
DIM ST$(7)
CLS
FOR I=1 TO 7
INPUT "Enter string"; ST$(I)
NEXT I
PRINT "The reverse string is :"; RE$(ST$())
DATA “Prabhu”, “Alok”, “Bimal”, “Suman”, “Ishwor”, “Om”, “Nitu”
END

FUNCTION RE$(ST$()))
FOR J = 1 TO 7
VR$ = VR$ + MID$(ST$(J), 1,1I)
NEXT J
RE$=VR$
END FUNCTION

3.      DECLARE FUNCTION OUT$(A$( ))
DIM A$(6)
FOR A = 0 to 5
READ A$(A)
NEXT A
DATA SARITA, JEHEN, RADHIKA, ISHIKA, DILIP, BRIJESH
PRINT OUT$(A$( ))
END

FUNCTION OUT$(A$( ))
CTR = 1
FOR R = 0 TO 5
T$ = T$ + MID$ (A$(R), CTR, 1)
CTR = CTR + 1
NEXT R
OUT$ = T$
END FUNCTION

4.      DECLARE FUNCTION answer$(x$)
CLS
Y$ = “Question”
PRINT answer$(Y$)
END

FUNCTION answer$(x$)
FOR I = LEN(x$) to 1 STEP – 4
Z$ = MID$(x$, I, 1) + Z$
NEXT i
answer$ = Z$
END FUNCTION

5.      DECLARE FUNCTION test$(a)
CLS
INPUT "Enter a number";a
PRINT test$(a)
END

FUNCTION test$(a)
WHILE a<>0
b=a mod 2
c$= str$(b)+c$
a=a\2
WEND
test$=c$
END FUNCTION
6.      DECLARE FUNCTION FIND (M, N)
READ X, Y
PRINT FIND (X, Y)
PRINT FIND (5, 10)
DATA 14, 8
END  

FUNCTION FIND (A, B)
IF A>B THEN SWAP A, B
Q= 0
FOR I = A TO B
IF I MOD 2=1 THEN Q=Q+1
NEXT I
FIND=Q
END FUNCTION

7.      DECLARE FUNCTION ABC(X)
CLS
FOR I=1 TO 8
READ N
Z=ABC(N)
S=S+Z
NEXT I
PRINT S
DATA 7, 22, 11, 34, 17, 52, 26, 13
END

FUNCTION ABC(X)
IF X MOD 2 < > 0 THEN ABC=X
END FUNCTION

8.      DECLARE FUNCTION ABC (N)
S = 0
FOR K=1 TO 6
V= ABC (K)          
PRINT  V
S = S + V
NEXT K
PRINT S
END
     
FUNCTION ABC (N)
IF N MOD 2 = 0 THEN
ABC = N*N
ELSE
ABC = 0
END IF
END FUNCTION


9.      DECLARE FUNCTION CHECK(A)
CLS
PRINT CHECK(4387)
END
FUNCTION CHECK(A)
WHILE A<>0
R=A  MOD 10
IF R MOD 2=0 THEN
S=S+R
END IF
A=A\10
WEND
CHECK=S
END FUNTION

10.   DECLARE FUNCTION CHECK (B)
A = 125
S = 0
CLS
PRINT “OUTPUT:::”;CHECK (A)
END

FUNCTION CHECK (B)
WHILE B<>0
C = B MOD 10
IF C MOD 2=1 THEN D = D + R^3
B = INT(B/10)
WEND
CHECK = D
END FUNCTION

11.   DECLARE SUB NUM( )
CLS
CALL NUM
END

SUB NUM()
A = 3
FOR I = 1 TO 10
PRINT A,
IF A MOD 2 < > 0 THEN
A = A*3+1
ELSE
A =A/2
ENDIF
NEXT I
END SUB

12.   DECLARE SUB Test2( )
CLS
CALL Test2
END

SUB Test2 ( )
N=7
WHILE N>1
PRINT N
IF N MOD 2 = 0 THEN
N = N / 2
ELSE
N = N * 3 + 1
END IF
WEND
PRINT N
END SUB


13.   DECLARE SUB RESULT(X,Y)
CALL RESULT(3,9)
END

SUB RESULT(X,Y)
FOR I = X TO Y
R=I MOD 2
IF R=1 THEN PRINT I
NEXT I
END SUB




14.   DECLARE SUB RSLT (A, B)
CALL RSLT (3, 15)
END

SUB RSLT (A, B)
FOR I = A TO B
R = I MOD 2
IF R = 0 THEN PRINT I
NEXT
END SUB

15.   DECLARE SUB DISPLAY(X)
CLS
FOR N = 1 TO 10 STEP 3
CALL DISPLAY (N)
NEXT N
END

SUB DISPLAY (X)
IF X MOD 2 =1 THEN PRINT X;
END SUB

16.   DECLARE SUB G(A, B)
CLS
FOR X = 1 TO 4
READ P, Q
CALL G(P, Q)
NEXT X
DATA 4, 5, 8, 6, 15, 10, 17, 19
END

SUB G(A, B)
IF A < B THEN
TH = A
ELSE
TH = B
END IF
PRINT TH
END SUB

17.   DECLARE SUB ABC(A)
CLS
FOR I = 1 TO 5
READ N
CALL ABC(N)
NEXT I
DATA 24, 15, 48, 18, 12
END

SUB ABC(N)
R = N MOD 4
R1 = N MOD 6
IF R = 0 AND R1 = 0 THEN
PRINT N
END IF
END SUB

18.   DECLARE SUB OUTPOOT()
CLS
CALL OUTPOOT
END

SUB OUTPOOT
I=1
N=10
DO
IF N MOD 2=0 THEN PRINT N
I=I+1
N=N+1
LOOP UNTIL I>9
END SUB

19.   DECLARE SUB SHOW ( )
CLS
CALL SHOW
END

SUB SHOW ( )
A = 10
DO WHILE A <= 45
S = A MOD 3 + 5
IF S MOD 3 < > 0 THEN GOTO AA
PRINT S;
AA:
A = A + 9
LOOP
END SUB

20.   DECLARE SUB COUNT$(W$)
REM ”THIS PROGRAM COUNTS TOTAL VOWELS”
INPUT "ENTER A SENTENCE”;S$
CALL COUNT(S$)
END

SUB COUNT(W$)
C=1
FOR I=1 TO LEN(W$)
c$=MID$(W$,I,1)
IF c$ = “ “ THEN C=C+1
NEXT I
PRINT ”The total number of word is”;C
END SUB

21.   DECLARE SUB TEST(A$)
CLS
A$ = “COMPUTER”
CALL TEST(A$)
END

SUB TEST(A$)
FOR I=1 TO LEN(A$)
B$=MID$(A$,I,1)
C=ASC(B$)
IF C MOD 2 =0 THEN
D$=D$+CHR$(C+32)
ELSE        
D$=D$+B$
ENDIF
NEXT I
PRINT D$
END SUB

22.   DECLARE SUB DISPLAY(S$)
CLS
A$=”MAAF”
DISPLAY A$
END

SUB DISPLAY(S$)
L=LEN(S$)
FOR I=L TO 1 STEP -1
VER$=MID$(S$, I, 1)
IF I MOD 2 =1 THEN
CON$=CON$+LCASE$(VER$)
END IF
NEXT
PRINT CON$
END SUB

23.  DECLARE SUB ABC (N$)
N$=”KATHMANDU”
CALL ABC (N$)
END

SUB ABC (N$)
CLS
N$=UCASE$(N$)
FOR J= 1 TO LEN (N$)
C$=MID$(N$, J, 1)
SELECT CASE C$
CASE “A”,”E”,”I”,”O”,”U”
X$=C$+X$
CASE ELSE
Z$=C$+Z$
END SELECT
NEXT J
PRINT Z$
END SUB

24.   DECLARE FUNCTION outp$(S$)
S$ = “KATHMANDU”
PRINT outp$(S$)
END

FUNCTION outp$(S$)
FOR I = 1 to LEN(S$)
t = I MOD 2
IF t = 1 then
W$ = W$ + UCASE$ (MID$(S$, I, 1)
ELSE
W$ = W$ + LCASE$ (MID$(S$, I, 1)
END IF
NEXT I
outp$ = W$
END FUNCTION


25.   DECLARE FUNCTION TEST$(A$)
CLS
a$="computer"
PRINT TEST$(A$)
END
FUNCTION TEST$(a$)
FOR K=1 TO LEN(A$)
B$=MID$(A$,K,1)
IF B$="a" OR B$="e" OR B$="i" OR B$="o" OR B$="u" THEN
C$=C$+UCASE$(B$)
ELSE
C$=C$+B$
END IF
NEXT K
TEST$ = C$
END FUNCTION

26.   DECLARE FUNCTION Reve$(S$)
S$ = “NEPS”
PRINT Reve$(S$)
END

FUNCTION Reve$(S$)
C$ = MID$ (S$, I, 1)
IF C$ = “ “ THEN
Reve$ = “ “
ELSE
FOR I = 1 TO LEN(S$)
ve$ = MID$ (S$, I, 1) + ve$
NEXT I
Reve$ = ve$
END IF
END FUNCTION

27.   DECLARE FUNCTION CONV$(D)
CLS
D = 509
PRINT CONB$(D)
END

FUNCITON CONV$(D)
WHILE D<>0
R = D MOD 16
IF R < 10 THEN
S$ = STR$(R) +S$
ELSE
S$ = CHR$(R+55) +S$
END IF
D = D\16
WEND
CONV$ = S$
END FUNCITON

28.   DECLARE FUNCTION VCOUNT(A$)
X$=”SCHOOL”
Y$=” INSTITUTE”
IF VCOUNT(S$)>VCOUNT(Y$) THEN PRINT X$ ELSE PRINT Y$
END

FUNCTION VCOUNT(A$)
N$=UCASE$(A$)
FOR X= 1 TO LEN(N$)
C$=MID$(N$,I,1)
IF C$=”A” OR C$=”E” OR C$=”I” OR C$=”O” OR C$=”U” THEN V=V+1
END IF
NEXT X
VCOUNT=V
END FUNCTION

29.   DECLARE FUNCTION PAB(S$)
CLS
R$=”Today is my computer exam”
PRINT PAB(R$)
END
FUNCTION PAB(S$)
C=1
FOR I = 1 TO LEN(S$)
A$=MID$(S$,I,1)
IF A$= “m” THEN C=C+1
NEXT I
PAB=C
END FUNCTION
30.   DECLARE FUNCTION CNT(ST$)
CLS
ST$ = “COMPUTER”
TOT = CNT(ST$)
PRINT TOT
END

FUNCTION CNT(ST$)
C = 1
DO WHILE C <= LEN(ST$)
A = ASC(MID$(ST$, C, 1)
S = S + A
C = C + 1
LOOP
CNT = S

END FUNCTION

No comments:

Post a Comment