100 HUNDRED PROGRAMMING QUESTIONS COLLECTIONS [FIND OUTPUT WITH DRY RUN, DEBUG, ANALYTICAL QUESTIONS QBASIC PROGRAMMING COLLECTIONS] – 2 + 2 + 2 = 6 MARKS
1. Write the
output of the following program.
DECLARE FUNCTION
Interest(p,t,r)
CLS
LET p=30
LET t=40
LET r=6
LET
d=Interest(p,t,r)
PRINT “The simple
interest will be”; d
END
FUNCTION
Interest(p,t,r)
answer =
(p*t*r)/100
Interest=answer
END FUNCTION
2. Write the output of the following
program:
DECLARE FUNCTION Interest(p,t,r)
CLS
LET p=100
LET t=2
LET r=5
LET d=Interest(p,t,r)
PRINT “The simple interest=”;d
END
FUNCTION Interest (p,t,r)
Interest=(p*t*r)/100
End FUNCTION
3. Write the
output of the following program:
DECLARE FUNCTION
AREA(L,B)
CLS
LET L =100
LET B = 20
LET ans=AREA(L,B)
PRINT “The
area=”,ans
END
FUNCTION AREA(L,B)
ar=L*B
AREA=ar
END FUNCTION
4. Write down the output of the following program:
DECLARE FUNCTION
area(L,B)
LET L=10
LET B=5
PRINT “The area=”; area(L,B)
END
FUNCTION area(L,B)
A=L*B
area=A
END FUNCTION
5. Write down
the output:
DECLARE FUNCTION AVGE(A,B,C)
X=10
Y=5
Z=15
AV= AVGE(X,Y,Z)
PRINT “Average of three numbers”; AV
END
FUNCTION AVGE(A, B, C)
S=A+B+C
AVGE = S/3
END FUNCTION
6. Write down the
output of the given program and show them in dry run table.
DECLARE FUNCTION
Series (N)
CLS
A=2
PRINT "Sum of
the series"; Series (A)
END
FUNCTION Series
(N)
Sum=0
FOR J = 1 TO 4
Sum=Sum + N
N=N+3
NEXT J
Series= Sum
END FUNCTION
7. Write down the output of the given program and show them
in dry run table:
DECLARE FUNCTION SQN (N)
CLS
S=0
FOR L=1 TO 3
READ NUM
S=S+SQN (NUM)
NEXT L
PRINT "Sum of square"; S
DATA 1, 4, 5
END
FUNCTION SQN (N)
SQN = N^2
END FUNCTION
8. Write the output of the following program:
DECLARE FUNCTION SQD(N)
CLS
S = 0
FOR L = 1 TO 3
READ NUM
S = S + SQD(NUM)
NEXT L
PRINT "Sum"; S
DATA 2,4,6
END
FUNCTION SQD (N)
SQD = N ^ 2
END FUNCTION
9. Write the output of the following program:
DECLARE FUNCTION test (N)
CLS
FOR Ctr = 1 TO 3
READ N
Sum = Sum + test (N)
NEXT Ctr
PRINT “The result=”; Sum
DATA 3, 2, 1
END
FUNCTION test (N)
Test = N^2
END FUNCTION
10. Write the output of the given program: Show
with dry run in
table.
DECLARE SUB SHOW(A)
CLS
N=87
CALL SHOW(N)
END
SUB SHOW(A)
DO
B=A MOD 6+3
IF B MOD 4=0 THEN GOTO AA
PRINT B;
AA:
A=A-10
LOOP WHILE A>=50
END SUB
11. Write down the output of the given program:
DECLARE SUB Series(A)
CLS
A=20
CALL Series(A)
END
SUB Series(A)
FOR K=1 to 5
PRINT A;
A=A+10
NEXT K
END SUB
12. Write the output of the given program: (Workout with a
dry run).
DECLARE SUB ABC(A)
CLS
A=2
CALL ABC(A)
END
SUB ABC(A)
FOR J= 1 TO 5
PRINT A;
A=A+3;
NEXT J
END SUB
13. Write the
output of the following program.
DECLARE SUB Series()
CALL Series
END
SUB Series
X=1
Y=1
FOR Z=1 TO 4
PRINT X;
Y=Y+1
X=X*10+Y
NEXT Z
END SUB
14. Write the output of the following program:
DECLARE SUB series()
CALL series
END
SUB series
X = 1
FOR K = 1 TO 4
PRINT X;
X = X + K
NEXT K
END SUB
15. Write
the output of the following program.
DECLARE SUB
Series()
CLS
CALL Series
END
SUB Series
A=1
B=1
FOR I =
1 TO 2
PRINT
A; B;
A=A+B
B=A+B
NEXT I
END SUB
16. Write
the output of the following program.
DECLARE SUB
Series()
CLS
CALL Series
END
SUB Series
A=2
B=2
FOR ctr
= 1 TO 2
PRINT
A; B;
A=A+B
B=A+B
NEXT
ctr
END SUB
17. Write the
output of the following program
DELARE SUB
NUMBER()
CLS
CALL NUMBER
END
SUB NUMBER
N=3
C=1
WHILE C<=5
PRINT
N
N=N*10+3
C=C+1
WEND
END SUB
18. Write the output of the given program:
DECLARE SUB CHECK (N)
CLS
N = 1436
CALL CHECK (N)
END
SUB CHECK (N)
DO WHILE n< >0
R = N MOD 10
S = S*10+R
N = N\10
LOOP
PRINT "NOW N BECOMES"; S
END SUB
19. Write the output of the following
program. [2]
DECLARE FUNCTION SUM ( a )
CLS
a = 9
PRINT SUM ( a )
END
FUNCTION SUM ( a )
FOR K = 1 to a
IF K MOD 2 = 0 THEN
S = S + K
END IF
NEXT K
SUM = S
END FUNCTION
20. FIND OUTPUT
DECLARE SUB SERIES ()
CLS
CALL SERIES
END
SUB SERIES ( )
X=1
Y=2
FOR P =1 TO 10
PRINT X;
X=X+Y
Y=Y+1
NEXT P
END SUB
21. Write the
output of the given program:
DECLARE SUB
Result
CALL Result
END
SUB Result
For I = 1 to 9 STEP 2
Sum=Sum +I^2
Next I
PRINT Sum
END SUB
22. Write the output of the following programs:
DECLARE SUB Series ()
CALL Series
END
SUB Series
X = 0
FOR K = 10
TO 4 STEP -2
A
= K ^2
X = X + A
NEXT K
PRINT X
END SUB
23. Write down the output of the given program.
Show with dry run in table
DECLARE SUB SERI()
CLS
CALL SERI
END
SUB SERI
X# = 1
FOR I = 1 TO 5
PRINT X# * X#
X# = X# * 10 +1
NEXT I
END SUB
24. Write the output of the following program:
DECLARE SUB REMINDER (R)
CLS
FOR I = 1 TO 4
READ X
CALL REMINDER (X)
NEXT I
DATA 56, 28, 8, 48
END
SUB REMINDER (R)
R1 = R MOD 4
R2 = R MOD 3
IF R1 = 0 AND R2<> 0 THEN
PRINT R
END IF
END SUB
25. Write the
output of the given program showing the dry run table. (2)
DECLARE FUNCTION
OUT (A, B)
CLS
A=17
B=7
PRINT OUT (A, B)
END
FUNCTION OUT (A,
B)
R=A MOD B
IF R MOD 2=0 THEN
C=R MOD 6+30
ELSE
C=R MOD 6+15
ENDIF
D=C\5
OUT=D
END FUNCTION
26. Write the
output of the following program showing necessary rough:
DECLARE SUB
DISPLAY ( )
CLS
CALL DISPLAY
END
SUB DISPLAY
LET N = 100
DO UNTIL N < 50
R=N MOD 9+3
IF R MOD 4=0 THEN
GOTO BOTTOM
PRINT R
BOTTOM:
N=N-10
LOOP
END SUB
27. Write down the output of the given
program. \Show with dry run in table.
DECLARE SUB SERU (
)
CLS
CALL SERU
END
SUB SERU ( )
X=2
C=1
WHILE C<=10
S=X^C
PRINT S;
C=C+1
WEND
END SUB
28. Write the output of the following program. [2]
DECLARE SUB series ()
CALL series
END
SUB series ()
i = 3
FOR c = 1T0 5
PRINT i *c^2;
NEXT c
END SUB
29. Write the
output of the given program showing the dry run table. (2)
DECLARE SUB test()
CALL test
END
SUB test
X=0
FOR K=10 TO 4
STEP-2
A=K^2
X=X+A
NEXT K
PRINT X
END SUB
30. Write down the
output of the given program and show them in dry run table:
DECLARE SUB SERIES
( )
CLS
CALL SERIES
END
SUB SERIES ( )
X = 1
Y = 1
FOR P = 1 TO 10
PRINT X;
X = X + Y
Y = Y + 1
NEXT P
END SUB
31. Write down the
output of the given program. Show with dry-run in table.
CLS
P=1: Q=1
CALL DISP(P,Q)
END
SUB DISP(M,N)
WHILE (N<=5)
PRINT M
M=M*10+N
N=N+1
WEND
END SUB
32. Write down the output of the given program. Show in dry
run table.
DECLARE SUB Result (C$)
C$= “COMPUTER"
CALL Result (C$)
END
SUB Result (C$)
FOR C=1 TO LEN(C$) STEP 2
M$=MIDS (C$,C,1)
N$=N$+MS
NEXT C
PRINT N$
END SUB
33.
Write the output of the following program: [2]
DECLARE SUB Display (T$)
CLS
T$ = "COMPUTER"
CALL Display (T$)
END
SUB Display (T$)
FOR C = 1 to LEN (T$) STEP 2
D$ = MID$(T$, C, 1)
PRINT D$;
NEXT C
END SUB
34.Write the
output of:
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
35. Write the
output of the following program.
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
36. Write down the
output of the given program.
\Show with dry run in table. (2)
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
37. FIND OUTPUT
DECLARE SUB Show (XY$)
CLS
XY$ = "HTUOMENXSA"
CALL Show(XY$)
END
SUB Show(XY$)
A = 47
FOR I = 1 TO 5
N = A
MOD 7
PRINT
MID$(XY$, N, 1)
A = A
- 1
NEXT I
END SUB
38. Write down the
output of the given program:
DECLARE SUB SERIES
( )
CALL SERIES
END
SUB SERIES
N$ = “*”
FOR 1 TO 5
FOR J=1 TO I
PRINT N$;
NEXT J
PRINT
NEXT I
END SUB
1. Re-write the given program after correcting
the
bugs:
REM to add record in an existing file
CLS
OPEN “Record.Dat” FOR OUTPUT AS #1
AA:
INPUT “Enter Name, Class and Roll No.”; Nm$, Cl, Rn
INPUT #2, Nm$, Cl, Rn
INPUT “More records”; Y$
IF UCASE$(Y$)=”Y” THEN GOTO aa
CLOSE “Record.dat”
END
2. Debug the given program:
OPEN "STUDENT.DAT" FOR APPEND AS 1#
INPUT "NAME"; N$
INPUT "ADDRESS"; ADD$
INPUT "AGE"; AGE$
WRITE #1, N$, ADD$, AGE
END# 1
STOP
3. Re-Write the
given program after correcting the bags:
REM to display
name, post and salary of 10 employees
OPEN
"EMP.TXT" FOR IN AS #1
FOR I=10 TO 1
INPUT #1, Name$,
Post$, Salary
DISPLAY Name$,
Post$, Salary
NEXT I
CLOSE “EMP.TXT”
END
4. Rewrite the given program after correcting the bugs:
REM to display records from existing file.
OPEN "emp.text" FOR APPEND AS #1
WHILE NOT EOF (#1)
WRITE # 1, eN$, posts, salaryS
PRINT eN$, post$, salary
NEXT
CLOSE #1
END
5. Rewrite the
following program after correcting the bugs:
REM to store Name,
post and salary
OPEN EMP.DOC FOR OUT AS #1
INPUT “Enter Name”; N
INPUT “Enter post”; P$
INPUT “Enter salary”; S
WRITE #2, N$,P$,S
CLOSE #1
END
6. Rewrite the
given program after correcting the bugs.
REM to display all the records from sequential Rem data file ABC.DAT
OPEN “ABC.DAT” FOR OUTPUT AS # 1
DO WHILE NOT
EOF(“ABC.DAT”)
INPUT # 1,N$,A
PRINT N$,A
CLOSE 1
END
7. Rewrite the
following program after correcting the bugs.
Rem to display the
contents of a data file.
OPEN “Marks.dat” FOR OUTPUT AS #1
CLS
WHILE EOF(1)
INPUT
#1, Name$, Age, Add$
DISPLAY
Name$, Age, Add$
WEND
CLOSE 1
END
8. Rewrite the
given program after correcting the bugs:
REM display
Records of students From Data File
OPEN “STDREC.DAT”
FOR INP AS #1
PRINT
“ROLL”,”NAME”,”ADDRESS”,”CLASS”,”SECTION”
DO WHILE NOT EOF
INPUT
#1,RN,N$,AD$,CL,S$
PRINT
RN,N$,AD$,CL,S$
NEXT
CLOSE #1
END
9. Rewrite the given program after correcting
the bugs. [2]
REM program to read data from the data file.
OPEN “STD.DAT” FOR OUTPUT AS #1
CLS
WHILE NOT EOF(#1)
WRITE#1, N$, R, C, P
PRINT N$, R, C, P
WEND
CLOSE “STD.DAT”
END
10. Re-write the given program after correcting
the bugs:
Rem To print only class 10 record from
"student.dat"
CLS
OPEN "I",#2, "Student.Dat"
WHILE NOT EOF (#2)
WRITE#2, N$,C,R
IF C=10 THEN
DISPLAY N$,C,R
END IF
NEXT
CLOSE #2
END
11. Re-write the
following program after correcting:
DECLARE FUNCTION
SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number; y
PRINT SUM(a,b)
END
FUNCTION SUM(x,y)
SUM=a+b
END
12. Re-write
the following program after correcting the bugs:
FUNCTION SUM(m,n)
Rem to print sum of two numbers
a=6
b=7
DISPLAY SUM(a,b)
END
FUNCTION SUM(m,n)
S=m+n
S=SUM
END SUM
13. Re-Write the given program after correcting the bugs:
DECLARE SUB Square (A)
REM to print square of a input number
CLS
GET "Enter a number"; N
Square (N)
END
SUB Square (A)
Sq = A^ 4
Display "Square of a number is "; Sq
End Sub
14. Re-write the given program after
correcting the bugs:
CREATE FUNCTION Square(A)
Rem to print square of a number
CLS
Get “a number”; A
CALL square(A)
END
FUNCTION square(A)
Ans=A^2
Square=Ans
END Square(A)
15. Re-write the given program after correcting the
bugs:
DECLARE SUB Series ( )
CLS
EXECUTE Series
END
SUB Series( )
REM Program to generate 1 1 2 3 5 .....upto the 20th terms
A=1
B=1
FOR ctr=10 to 1
DISPLAY A:B:
A=A+B
B=A+B
NEXT ctr
END Series ( )
16. Re-write the
given program correcting the bugs:
DECLARE SUB
Series()
CLS
EXECUTE Series
END
SUB Series
A=2
B=2
FOR ctr= 1 to 5
DISPLAY
A;B;
A=A+B
B=A+B
LOOP
ctr
END Series()
17. Debug the
given program:
DECLARE SUB Fibonic()
REM *Fibonic series*
CALL SUB Fibonic
END
SUB Fibonic
a=1
b=1
FOR x=1 to 10
DISPLAY a;
a=a+b
b=a+b
END Fibonic
18. Rewrite the
following program after correcting the bugs:
DECLARE SUB Series()
CLS
EXECUTE Series
END
SUB Series()
REM
program to generate 1 1 2 3 5…. Up to 20th terms
A=1
B=1
FOR
ctr= 10 TO 1
DISPLAY
A;B;
A=A+B
B=A+B
EXT
ctr
END Series()
19. Rewrite the
following program after correcting the bugs:
2
DECLARE SUB Series(.)
DLC
EXECUTE Series
END
SUB Series
REM to
generate 2 2 4 6 10….. upto 10th term
P=2
Q=2
FOR Ctr=1
TO 5
DISPLAY
P,Q,
P=P+Q
Q=P+Q
WEND
END Series()
20. Re-write the given program after correcting
the bugs:
DECLARE SUB FIBO ( )
CLS
EXECUTE FIBO
END
SUB FIBO
REM Program to generate 2, 2, 4, 6, 10…upto 10th terms.
A=2
B=2
FOR Ctr = 5 TO 1
DISPLAY A; B;
A=A+B
B=A+B
NEXT Ctr
END FUNCTION
21. Re-write the given program after correcting
the bugs:
DECLARE SUB Series ( )
CLS
EXECUTE Series
END
SUB Series
REM Program to print 4 4 8 12 20 ....... 20th
terms
X = 4
Y = 4
FOR ctr = 10 To 1
DISPLAY X; Y;
X = X+Y
Y = X+ Y
Next ctr
End Series
22. Re-write the following correcting
the bugs:
DECLARE SUB CUBE(N)
CLS
FOR I = 1 TO 5
READ
CALL CUBE(No)
NEXT X
DATA 3, 5, 2, 6, 4
END
SUB CUBE( )
DISPLAY N^3
END SUB
23.
Re-write the given program after correcting the bugs: [4×0.5=2]
REM TO find the factorial of a given number.
DECLARE FUNCTION FACTO (N$)
CLS
INPUT "Enter a number"; X
PRINT "The Factorial is: ", FACTO (N)
END
FUNCTION FACTO (N)
F = 1
WHILE N = 0
F = F * N
N = N - 1
WEND
F = FACTO
END FUNCTION
24. Re-write the given program after correcting
the bugs:
DECLARE SUB SUM(N)
INPUT “Any Number”; N
PRINT SUM(N)
END
SUB SUM (N)
S=0
WHILE N=0
R= R MOD 10
S=S+R
N=N/10
WEND
PRINT “Sum of digits”;S
END
25. Re-Write the given program after correcting the bugs:
REM program to make a word reverse
DECLARE FUNCTION Rev$(N$)
CLS
LNPUT “Enter a word”; N$
DISPLAY “Reversed is”; Rev$(N$)
END
EUNCTION Rev$(N$)
FOR K=LEN$(N$) To 1 STEP-1
B$=B$+MID$(N$,1,K)
NEXT K
B$=Rev$
END FUNCTION
26. Re-write
the given program correcting the bugs:
Rem program to
reverse the string or word
DECLARE SUB
REV(W$)
CLS
INPUT “Enter a
wod”;W$
CALL REV(W$)
END
SUB REV(W$)
FOR I=LEN(W$) to 1
step -1
C$=LEFT$(W$,I,1)
S$=D$+1
LOOP
PRINT “Reverse
string is:”; D$
CLOSE SUB
27. Re-Write the given program after correcting
the bugs:
DECLARE FUNCTION reverse$(N$)
INPUT “Any String”; N$
X$ = reverse$(N$)
PRINT N$
END
FUNCTION reverse(N$)
L = LEN$(N$)
FOR X = L to 1 STEP – 1
A$ = MID$(N$, X, I)
B$ = B$ + A$
NEXT X
B$ = reverse$(N$)
END FUNCTION
1. Study the following program and answer the
given
questions. [2×1=2]
OPEN “Detail.dat” FOR INPUT AS #1
OPEN “Temp.dat” FOR OUTPUT AS #2
INPUT “Enter name of the students”; S$
FOR I=1 TO 10
INPUT #1, Nm$, Cl, A
IF S$< >Nm$ THEN
WRITE #2, Nm$, Cl, A
END IF
NEXT I
CLOSE #1, #2
KILL “Detail.dat”
NAME “Temp.dat” AS “Detail.dat”
END
a. What is the main
objective of the program given above?
b. Do you get any
problem in the above program if “Kill” statement is removed? Give reason.
2. Study the following
program and answer the given questions:
DECLARE SUB SEE
(A$)
A$="COMPUTER
SCIENCE”
END
SUB SEE (A$)
L=LEN(A$)
FOR I=L TO 1
STEP-2
PRINT MID$ (A$, I,
1)
NEXT I
END SUB
a) Which statement
should be added in the main module to execute the program?
b) List out the
variables used in the above program.
3. Study the following program and answer the given
questions:
DECLARE FUNCTION Count (W$)
INPUT "Enter a word"; R$
C = Count (R$)
PRINT C
END
FUNCTION Count (W$)
FOR L = 1 TO LEN (W$)
Ch$=MID$ (W$, L, 1)
IF UCASES (Ch$) = "K" THEN
N=N+1
END IF
NEXT L
Count = N
END FUNCTION
a) List any two library functions used in the above program.
b) Write the use of variable 'C' in line 3 [i.e. C = Count
(R$)] given in the above program.
4. Study the following program and answer the given
questions:
DECLARE FUNCTION SUM(N)
CLS
INPUT “Enter any number”; N
X=SUM(N)
PRINT “The sum of individual digit is “; X
END
FUNCTION SUM(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=INT(N/10)
WEND
SUM=S
END FUNCTION
a) Write the function of INT.
b) How many times does the WHILE ….WEND loop repeat if the
value of N is 123?
5. Read the
program given below and answer the following questions.
DECLARE SUB SUM(N)
INPUT”ANY NUMBER”;N
CALL SUM(N)
END
SUB SUM(N)
S=0
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT “SUM”;S
END SUB
i) In which condition the statements within the WHILE….WEND looping
statement will not be executed?
ii) Will the
output be the same if we place “/” instead of”\” in the above program.
6. Study the following program and answer the given
questions.
DECLARE FUNCTION prod (A,B)
CLS
INPUT “Enter first number'; A
INPUT ‘Enter second number"; B
PRINT ‘“The product of the two number="; prod (A,B)
END
FUNCTION prod (A,B)
P=A*B
prod=P
END FUNCTION
List all the numerical variables used in the program
above.
List the local variables used in program above.
7. State the following program and answer the
given questions:
DECLARE FUNCTION Diff(A, B)
CLS
INPUT “Enter first number”; A
INPUT “Enter second number”; B
PRINT “The difference”; Diff(A, B)
END
FUNCTION Diff(A, B)
Difference= A – B
Diff = difference
END FUNCTION
List all the numeric variables used in the above
program.
List the local variables used in the above
program.
8. Study the following program and answer the
given questions:
DECLARE FUNCTION SUM (A, B)
INPUT A
INPUT B
X = SUM (A, B)
PRINT X
END
FUNCTION SUM (A, B)
S = A+B
SUM = S
END FUNCTION.
a) Write
the name of local variable used in the above FUNCTION procedure.
b) Write
the Mathematical operator and Relation operator used in above program.
9. Study the following program and answer the given
questions. 2x1=2
DECLARE FUNCTION TEST(X)
X=100
Z=TEST(X)
PRINT Z
END
FUNCTION TEST(X)
FOR R=1 TO X
S=S+I
NEXT R
TEST=S
END FUNCTION
a) How many parameters are used in the above program?
b) How many times does the statement S=S+I execute in the
above program?
10. Study the
following program and answer the following question:
DECLARE FUNCTION xyz(N)
FOR I = 1 TO 5
READ N
Z=xyz(N)
S=S+Z
NEXT I
PRINT S
DATA 10,13,15,4,6
END
FUNCTION xyz(N)
IF N MOD 2=0 THEN xyz=N
END FUNCTION
a) What is the name of the function used in the above program?
b) How many times
the function will be called in the above program?
11. Read the given
program and answer the following questions:
DECLARE FUNCTION Num(N)
INPUT N
S=Num(N)
PRINT S
END
FUNCTION Num(N)
X=Int(17/N)
Y=15 MOD N
Num=X +Y
END FUNCTION
i) Write the name
of the function used in the above program.
ii) List out the
mathematical function (Library function) used in the above program.
12. Study the following program and answer the
given questions:
DECLARE
FUNCTION JPT (N)
FOR
ctr = 1 TO 6
READ
N
J
= JPT (N)
Sum
= Sum + J
NEXT
ctr
PRINT
Sum
DATA
10, 20, 30, 40, 50, 60
END
FUNCTION
JPT (N)
IF
N MOD 2 = 0 THEN JPT = N
END
FUNCTION
a) What
is name to the function used in the above program?
b) How
many times the function will be executed in the above program?
13. Study the following program and answer the
given questions. [2×1=2]
DECLARE SUB TEST (N$ )
INPUT N$
CALL TEST ( N$ )
END
SUB TEST (N$ )
FOR P = 1 TO LEN ( N$ )
B$ = MID$ (N$, P, 1)
IF LCASE$ (B$) = “a” THEN
C = C + 1
END IF
NEXT P
PRINT C
END SUB
a) Write
the name of the sub procedure used in the above program.
b) Write
any two library functions used in the above program.
14. Study the following program and answer the
given questions:
DECLARE SUB SUM(N)
N = 5
CALL SUM (N)
END
SUB SUM(N)
FOR X = 1 TO N
S =S + X
NEXT X
PRINT S
END SUB
a) In
the above program how many times does the FOR ………..NEXT loop executes?
b) Write
the name of the procedure used in the above program.
15. Study the
following program and answer the following questions:
DECLARE FUNCTION Prod(N)
INPUT “Any number”;N
X=Prod(N)
PRINT X
END
FUNCTION Prod(N)
F=1
FOR K=1 TO N
F=F*K
NEXT K
Prod=F
END FUNCTION
a) Write
the name of the user defined function used in the above program.
b) Name
the loop in the above program.
16. Study the
following program and answer the following questions:
DECLARE FUNCTION
COUNT(A$)
Input “Enter a word”; W$
END
Function Count(A$)
B=LEN(A$)
C$=UCASE$(A$)
FOR I=1
TO B
E$=MID$(C$,I,1)
IF E$=”A” OR E$=”E” OR E$=”I” OR E$=”O” OR E$=”U”
THEN C=C+1
END IF
NEXT I
COUNT=C
END FUNCTION
a) List the string Library functions used in the above program.
b) Write down the
missing statements in the main module to execute the program.
17. Study the
following program and answer the given questions:
DECLARE SUB
EXAM(N$)
CLS
INPUT “Enter
word”;WO$
CALL EXAM(WO$)
END
SUB EXAM (N$)
FOR I = 1 TO LEN
(N$)
PRINT RIGHT$(N$,I)
NEXT I
END SUB
a) Write the names
of two built-in functions used in the above program.
b) List the real
parameter in the program.
18. Study the following programs and answer the
question:
DECLARE FUNCTION rev$ (N$)
INPUT
"Any string"; N$
PRINT
rev$ (N$)
END
FUNCTION rev$ (N$)
FOR
X = LEN (N$) to 1 STEP -1
A$=MID$
(N$, X, 1)
B$
= B$ + A$
NEXT
X
rev$
= B$
END FUNCTION
a. List
the library function used in the above program.
b. What
will be the maximum value of X if the N$ is equal to "Computer".
19. Study the following program and
answer the following:
DECLARE SUB Stde(N$U)
FOR Loop = 1 TO 5
READ NM$(Loop)
NEXT Loop
DATA RAMA, PRATIMA, PRASANT
DATA NISHA, RUDHRA
CALL Stde(NM$U)
END
SUB Stde(N$U)
PRINT “Name starting from P”
FOR J = 1 TO 5
C$=MID$(N$,(J),1,1)
IF C$=”P” THEN
PRINT N$(J)
END IF
NEXT J
END SUB
List the library function used in the
above program.
List the conditional statement used in the above
program is:
20. Analyse the
program given below and answer the questions:
DECLARE FUNCTION
Diff(A,B)
CLS
INPUT “Enter first
number”;A
INPUT “Enter
second number”;B
PRINT “The
difference of the two number=”;Diff(A,B)
END
FUNCTION Diff(A,B)
D=A-B
Diff=D
END FUNCTION
a) What will be
the output of the program if the user enters 200 as the first number and 100 as
the second number?
b) Will the
program run if the first line (i.e. DECLARE…..) is deleted?
21. Analyse the
program and answer the following question:
DECLARE SUB
ABC(X,Y,Z)
FOR P=1 TO 3
READ
A,B,C
CALL ABC(A,B,C)
NEXT P
DATA
5,4,3,2,1,6,7,8,4
END
SUB ABC(X,Y,Z)
T=X+Y+Z
IF
T MOD 2 = 0 THEN
PRINT
T
END
IF
END SUB
a) List
any two variables used in the above program.
b) How
many times SUB-procedure will be called when program is executed?
22. Analyse
the program given below and answer the questions:
DECLARE FUNCTION
CHK$(N)
CLS
N=57
PRINT “The number is”; CHK$(N)
END
FUNCTION CHK$(N)
FOR I =
1 TO N
IF
N MOD I = 0 THEN C=C+1
NEXT I
IF
C>2 THEN
CHK$=”Composite”
ELSE
CHK$=”Prime”
END IF
END FUNCTION
a) Will
the above program execute if “DECLARE FUNCTION….” is deleted?
b) Why
$ sign is used in the name of the above function.
23. Study the following
program and answer the questions: 1×2=2
DECLARE FUNCTION
Sum(A,B)
INPUT “Enter first
number:”; A
INPUT “Enter second
number:”; B
PRINT “The sum of the
two number=”;Sum(A,B)
END
FUNCTION SUM(A,B)
S=A+B
Sum=S
END FUNCTION
a) List the numerical
variables used in the above program.
b) Will the program run
if the first line (i.e. DECLARE….) is deleted?
24.
Study the following program and answer the given questions: [2×1=2]
DECLARE FUNCTION SUM (N)
CLS
INPUT "Enter any number"; N
S = SUM (N)
PRINT "The Sum of individual digit is"; S
END
FUNCTION SUM (N)
WHILE N > 0
R = N MOD 10
T = T + R
N = N \ 10
WEND
SUM = T
END FUNCTION
a) State the purpose of suing variable S in line 4 in above program.
b) Write the use of MOD in the above program.
25. Study the following
program and answer the given questions:
DECLARE SUB TRIM(W$)
CLS
INPUT "Enter word"; WO$
CALL TRIM(WO$)
END
SUB TRIM (W$)
FOR I = 1 TO LEN(W$)
PRINT LEFT$(W$, I)
NEXT I
END SUB
a) What
will be the maximum value of I if input string is “SEE” in the above program?
b) List
the real parameter used in the above program.
25. Read the following program and answer the
following questions:
OPEN
"BUSRIDER.TXT" FOR INPUT AS #1
OPEN
"TEMP.TXT" FOR OUTPUT AS #2
CLS
WHILE NOT EOF (1)
INPUT #1.
STUDENTNAME$, CLASS, BUSCODE, BUSSTOP$
IF
UCASE$(BUSSTOP$) < > UCASE$("KATHMANDU") THEN
WRITE #2,
STUDENTNAME$, CLASS, BUSCODE, BUSSTOP$
PRINT
STUDENTNAME$, CLASS, BUSCODE, BUSSTOP$
END IF
WEND
CLOSE #1, #2
KILL"BUSRIDER.TXT"
NAME
"TEMP.TXT" AS "BUSRIDER.TXT"
END
a) What is the
main objective of the program given above?
b) Do you get any
problem in above program if "Kill" statement is removed? Give
reason.
26. Study the
following program and answer the given questions:
DECLARE SUB TEST
(A, B, C)
LET X=4
LET Y=7
LETZ=12
CALL TEST (X, Y,
Z)
PRINT X, Y, Z
END
SUB TEST (A, B, C)
A=A+3
B-B+2
SUM=A+B+C
PRINT SUM
END SUB
a. List the
arguments and parameters used in the above program.
b. List local
variables used in each module.
27. Study the following
program and answer the given questions: 2x1=2
DECLARE FUNCTION
SUM (N)
CLS
INPUT “ENTER
MULTIDIGIT NUMBER”; A
SU = SUM(A)
PRINT “SUM OF
DIGITS”; SU
END
FUNCTION SUM(N)
S = 0
WHILE N < >
0
R = N MOD 10
S = S + R
N = N \ 10
WEND
SUM = S
END FUNCITON
a. What is the
name of the function used in the above program?
b. List the formal
and real parameters used in the above program.
28. Study the
following program and answer the given questions: 2x1=2
DIM N (10)
DECLARE SUB MIN (N
( ))
CLS
FOR I=1 TO 10
INPUT "ENTER
A NUMBER"; N (I)
NEXT I
CALL MIN (N ( ))
END
SUB MIN (N ())
S=N (1)
FOR 1=2 TO 10
IF SN > N(I)
THEN S=N (I)
NEXT I
PRINT "THE
SMALLEST NUMBER=”;S
END SUB
a. Which is array
variable in above program?
b. Which is
control statement in above program?
29. Study the following program and answer the given
questions:
(2´1=2)
DECLARE SUB
RESULT(A$)
A$="COMPUTER"
CALL RESULT(A$)
END
SUB RESULT(A$)
FOR I= 1 TO
LEN(A$) STEP 2
X$=MID$(A$,C, I )
PRINT X$;
NEXT I
END SUB
Questions:
a) List the
library functions used in above program.
b) How many times
loop executes in above program.
30. Study the following program and answer the given
questions:
(2´1=2)
DECLARE SUB
FACTORS(N)
N=10
CALL FACTORS(N)
END
SUB FACTORS(N)
FOR J=1 TO N
R=N MOD J
IF R=0 THEN PRINT
J;
NEXT J
END SUB
Questions:
a) Write down the
use of MOD in the program.
b) How many time
the loop executes in the above program?
31. Study the following program and answer the
given questions: (2x1=2)
REM “to count vowels”
DECLARE FUNCTION count (A$)
INPUT "Enter a word"; A$
End
FUNCTION count (A$)
B=LEN (A$)
C$=UCASE$(A$)
FOR I=1 to B
E$=MID$(C$, I, 1)
IF E$="A" or E$= "E" or E$=
"I" or E$="O" or E$ = "U" THEN
C=C+1
END IF
NEXT I
Count=C
END FUNCTION
Questions:
a) List the string library functions used in the
above program.
b) Write down the missing execute the program.
statements in the main module to execute the program.
32. Study the following program and answer the
given questions: (2x1=2)
DECLARE SUB TEST
(B$)
CLS
INPUT W$
CALL TEST (W$)
END
SUB TEST (B$)
FOR I =1 To LEN
(B$)
PRINT RIGHT$(B$),
i)
NEXT I
END
SUB
Questions:
a) Write the name of two built in functions
used in the above program.
b) List the real parameters of the above
program.
33. Study the following program and answer the
given questions:
DECLARE FUNCTION ODDEVEN$(N)
CLS
INPUT "Enter a number"; N
PRINT "Number is"; ODDEVEN$(N)
END
FUNCTION ODDEVEN$(N)
IF N MOD 2=0 THEN
MS$="even"
ELSE
MS$="odd"
END IF
ODDEVEN$=MS$
END FUNCTION
Questions:
a) What is the main objective of the above
program?
b) What is the use of MOD in the above
program?
34. Study the following programs and answer the given
questions:
DECLARE SUB question (a, b, c)
CLS
x=10: y=20 : z=15
CALL question(x,y,z)
END
SUB question(a,b,c)
a = a +10
b = b + a
c = a + b
PRINT a,b,c
END SUB
a) What would be its output if x=1,
y=2, z=3?
b) Write actual and formal
parameters used in the program.
35. Study the following program and answer the given
questions:
DECLARE FUNCTION text$(N$)
CLS
INPUT "Enter any string":X$
PRINT text$(X$)
END
FUNCTION text$(N$)
FOR i=len (N$) TO 1 STEP-1
W$=W$+MID$(N$,i,1)
NEXT i
text$ = WS
NEXT Q
END FUNCTION
a) What is the main objective of above program?
b) List all the parameters used in above program.
No comments:
Post a Comment