0% found this document useful (0 votes)
5 views5 pages

QBASIC Program Analysis and Output

The document contains multiple QBASIC programs with various functions and subroutines, along with questions related to their outputs and logic. It covers topics such as variable usage, function declarations, loops, and mathematical operations. Each section requires the reader to analyze the code and answer specific questions about its behavior and output.

Uploaded by

raneerizal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

QBASIC Program Analysis and Output

The document contains multiple QBASIC programs with various functions and subroutines, along with questions related to their outputs and logic. It covers topics such as variable usage, function declarations, loops, and mathematical operations. Each section requires the reader to analyze the code and answer specific questions about its behavior and output.

Uploaded by

raneerizal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

QBASIC Questions: PRINT NUM

Write the output of the given programs: NUM=NUM*10+2


DECLARE SUB RESULT () C=C+1
CALL RESULT WEND
END END SUB
SUB RESULT Study the following program and answer
N=5 the following question:
C=1 DECLARE FUNCTION SUM(N)
WHILE C<=5 CLS
PRINT N INPUT “Enter any number:-“;NUM
N=N*10+5 S=SUM(NUM)
C=C+1 PRINT “Sum of digits=”;S
WEND END
END SUB FUNCTION SUM(N)
Study the following program and answer S1=0
the given questions: DO WHILE N>=0
DECLARE FUNCTION A(X) R=N MOD 10
X=5 N=INT(N/10)
Z=A(X) LOOP
PRINT Z SUM=S1
END END FUNCTION
FUNCTION A(X) a) Are N and NUM used for the same
FOR I = 1 TO X purpose? Explain.
S=S+I b) What will be the value of S1 if the
NEXT I value of NUM is 155?
A=S Write the output of the given program:
END FUNCTION DECLARE SUB SERIES()
a) How many parameters are used in CALL SERIES
the program? END
b) How many times does the statement SUB SERIES
S=S+I execute in the above program? A=1
Write the output of the given program: B=1
DECLARE SUB RESULT() PRINT A;B;
CALL RESULT C=A+B
END PRINT C
SUB RESULT() LET A=B
C=1 LET B=C
NUM=2 IF C<=15 THEN
WHILE C<=5 GOTO X
END IF Z=3
END SUB FOR A= 1 TO 10
Write the output of the program: PRINT (A^2)*Z;
DECLARE SUB CHECK() NEXT A
CLS END SUB
CALL CHECK Re-write the given program correcting the
END bugs:
SUB CHECK() DECLARE FUNCTION SUM(N)
REM SUB PROCEDURE WITHOUT LET N = 5
PARAMETERS S=SUM(5,5)
ST$=”*****” PRINT SUM=S
FOR I = 1 TO LEN(ST$) END
PRINT LEFT$(ST$,I) FUNCTION SUM(N)
NEXT I DO
END SUB TOTAL=TOTAL + N
Study the following program and answer N=N-1
the following question: WHILE N>0
DECLARE SUB WORD(N$) TOTAL = SUM
N$=”NEPAL” END FUNCTION
CALL WORD(N$) Study the given program and answer the
END questions:
SUB WORD(N$) DECLARE FUNCTION SHAPE(TXT$)
LET B=LEN(N$) CLS
LET C= 1 INPUT “Enter a string:”;T$
WHILE C<=B RV$=SHAPE(T$)
M$=MID$(N$,C,1) PRINT “The text in reverse order is”;R$
PRINT M$; END
C=C+2 FUNCTION SHAPE(TXT$)
WEND R$= “ ”
END SUB FOR I = LEN(T$) TO 1 STEP -1
a) What is the value of B in the above CU$=MID$(TXT$,I,1)
program? R$=R$+CH$
b) List out the numeric and string NEXT I
variable used in the above program. SHAPE = RT$
Write the output of the program: END FUNCTION
DECLARE SUB RESULT() a) What will be the output of the
CALL RESULT program?
END b) For what purpose LEN and MID
SUB RESUTL() function are used?
Write the output of the program: LOOP
CLS DIGITSUM=SM
CALL RESULT END FUNCTION
END a) How many variables are declared in
SUB RESULT() the program?
CLS b) What does R=N MOD 10 mean?
FOR A = 1 TO 5 Write down the output of the given
B=B*10+2 program:
PRINT B DECLARE SUB OUTPUT()
NEXT A CALL OUTPUT
END SUB END
Re-write the given program after SUB OUTPUT()
correcting the bugs: FOR I = 5 TO 10
DECLARE FUNCTION REV(ST$) FOR J= 1 TO 5
CLS PRINT (I+J)*10
INPUT “Enter a string”;S$ NEXT J
LET R$= REV$(ST$) PRINT
PRINT “The string in reverse is”; R$ NEXT I
END END SUB
FUNCTION REV$(ST$) Re-write the given program after
FOR I = LEN(ST$) TO 1 correcting the bugs:
RV$=RV$+MID$(ST$,I,1) DECLARE FUNCTION BINARY(N)
NEXT I CLS
RV$=REV$ INPUT “Enter any number=”;N
END FUNCTION PRINT “Result=”;BINARY()
Study the given program and answer the END
following questions: FUNCTION BINARY(A)
DECLARE FUNCTION DIGITSUM(NO) BASE=2
CLS WHILE A<>0
INPUT “Enter any number:-”; NUM R=A MOD BASE
S=DIGITSUM(NO) A=A/BASE
PRINT “The sum of digit=”;S B$=STR$(R)+B$
END WEND
FUNCTION DIGITSUM(NO) BINARY=VAL(B)
SN=0 END FUNCTION
DO WHILE N>=0
R=N MOD 10
SM=SM1+R
N=INT(N/10)
Study the following program and answer DECLARE FUNCTION VOWEL$(W$)
the given questions: CLS
DECLARE FUNCTION SQUARE(NUM) INTPU “Enter a word”;W$
CLS R$=VOWEL(W$)
INPUT “Enter a number=”;NUM PRINT R$
IF X*X=NUM THEN END
PRINT “No. is perfect square” FUNCTION VOWEL$(W$)
ELSE FOR P=1 TO LEN(W$)
PRINT “No. is not perfect square” E$=LEFT$(W$,P,1)
END IF R$=R$+E$
END NEXT P
FUNCTION SQUARE(NUM) VOWEL$(W$)=R$
SQ=SQR(NUM) END SUB
SQUARE=SQ Study the following program and answer
END FUNCTION the given questions:
a) For what purpose the function SQR is DECLARE SUB TEST()
used? DIM SHARED A$,B$,C$
b) Find the output of given program if CLS
the value of NUM is 5? FOR P= 1 TO 3
Write the output of the program: READ A$,B$,C$
DECLARE FUNCTION CONVERT(N) NEXT P
CLS DATA “BAGMATI” , “SAGARMATHA” ,
LET NUM=1010 “KOSHI”
D=CONVERT(NUM) CALL TEST
PRINT D END
END SUB TEST
FUNCTION CONVERT(N) L$=A$
DO UNTIL N=0 IF LEN(B$)>LEN(L$) THEN L$=B$
R=N MOD 10 IF LEN(C$)>LEN(L$) THEN L$=C$
S=R*2^Q+S PRINT L$
Q=Q+1 END SUB
N=INT(N/10) a) List the global variables used in the
LOOP above program.
CONVERT=S b) What is the output of the above
END FUNCTION program?
Re-write the following program after
correcting the bugs:
REM program to display a word having
vowels characters
Write the output of the following
program:
DECLARE SUB SHOW(S)
CALL SHOW(534)
END
SUB SHOW(N)
A=N MOD 10
B=N\10
C=B MOD 10
D=INT(N/100)
PRINT “Ans=”;A+C+D
END SUB
Study the given program and answer the
questions:
DECLARE FUNCTION BB(N)
FOR I = 1 TO 4
READ P
Y=Y+BB(P)
NEXT I
DATA 23, 45, 60, 12
PRINT Y
END
FUNCTION BB(N)
IF N MOD 2 = 0 THEN FIND=N
END FUNCTION
a) How many times function …….. end
function execute in above program?
b) Does the program execute, if
underlined statement is removed from the
main module?

You might also like