55 QBASIC DEBUGGING PROGRAMMING QUESTIONS COLLECTIONS 2081 - SEE COMPUTER SCIENCE
1. [SEE MODEL
SET]
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. [SEE 2080]
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
3. [SEE 2080 GI]
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. [SEE 2079]
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
5. [SEE 2079 GP]
REM to display records from existing file.
OPEN "emp.text" FOR APPEND AS #1
WHILE NOT EOF (#1)
WRITE # 1, eN$, posts, salary
PRINT eN$, post$, salary
NEXT
CLOSE #1
END
6. [SEE 2078]
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 ( )
7. [PABSON PB
2081]
REM to display the
data from sequential data file "marks.dat” having marks in english more
than 35
CLS
OPEN “marks.dat”
FOR OUTPUT AS#1
WHILE NOT EOF(2)
INPUT #1, N$, ENG,
NEP, SCI
ENG+NEP+SCI = TOT
IF TOT >35 THEN
PRINT N$, ENG, NEP, SCI
NEXT
CLOSE #1
END
8. [PABSON PQ
2081]
REM To store name, age and salary
in a sequential data file REC.DAT
CLS OPEN "Employee.dat"
FOR OUTPUT AS #1
DO
INPUT "Enter employee's
name"; N$
INPUT "Enter employee's
address"; A$
INPUT "Enter employee's
age"; Al
INPUT "Enter employee's
gender";G$
INPUT "Enter employee's
salary";S
WRITE #1,A$,AI,G$,S
INPUT "Add more
records(Y/N)";A
LOOP WHILE UCASE(A$)="Y"
CLOSE 1
END
9. [PABSON MT 2081 A]
REM to display greatest number
DECLARE GREAT FUNCTION (a, b, c)
ACCEPT a, b, c
PRINT GREAT (x, y, z)
END
FUNCTION GREAT (a, b, c)
IF a>b or a>c THEN
G=a
ELSEIF b>a AND b>c THEN
G=b
ELSE
G=c
NEXT
G=GREAT
END SUB
10. [PABSON MT 2081 B]
REM To check the supplied no. is
odd or even
DECLARE FUNCTION Check$ (X)
CLS
ACCEPT “ANY NUMBER:”; N
CALL Check$ (X)
END
SUB Check$ (N)
Y=2
R= Y MOD N
IF R=0 THEN
C$= “EVEN”
ELSE
C$= “ODD”
END
C$=Check$
END FUNCTION
11. [PABSON FT 2081 A]
CREATE FUNCTION
CUBE(A)
REM to print cube
of a number
CLS
Get "Enter a
number"; A
Call CUBE(A)
END
FUNCTION CUBE(A)
ANS=A^3
ANS=CUBE
END FUNCTION
12. [PABSON FT 2081 B]
CREATE FUNCTION
SQUA(A)
REM to print
square of a number
CLS
Get "Enter a
number"; A
Call SQUA(A)
END
FUNCTION SQUA(A)
ANS=A^2
8ANS=SQUA
END FUNCTION
13. [PABSON PB
2080]
REM display
records of students from sequential data file.
OPEN “STUDENT.DAT”
FOR INP AS #1
PRINT “SNO”,
“NAME”, “ADDRESS”, “CLASS”, “SECTION”
WHILE NOT EOF
INPUT #1, SN, N$,
AD$, C, SE$
PRINT SN, N$, AD$,
C, SE$
NEXT
CLOSE #1
STOP
14. [PABSON PQ
2080]
REM to count total
no. of passed student
WHILE NOT EOF()
OPEN
"pab.txt" FOR OUTPUT AS#1
INPU
T#2,ID,M1,M2,M3
IF M1>=32,
M2>=32, M3>=32 THEN
X=X+1
END IF
WEND
PRINT "TOTAL
RECORD";X
END
15. [PABSON MT
2080]
DECLARE SUB S$ ( )
CLS
EXECUTE SS
END
SUB SS
REM Program to generate 2 2 4 6 10 .....upto the 10th terms
A=2
B=2
FOR JN=10 to 1
DISPLAY A;B;
A=A+B
B=A+B
NEXT JN
END S$ ( )
16. [PABSON FT 2080]
CREATE FUNCTION Square(A)
REM to print
square of a number
CLS
Get "Enter a
number"; A
Call Square(A)
END
FUNCTION Square(A)
Ans=A^2
Square=Ans
END Square(A)
17. [PABSON 2079
A]
FUNCTION SUM(M, N)
REM to print sum of two numbers
A=6
B=7
DISPLAY sum(M,N)
END
FUNCTION SUM(M,N)
S=M+N
S=SUM
END FUNCTION
18. [PABSON 2079
B]
REM To store name and age in a
sequential data file STD.DOC
OPEN STD.DOC FOR OUT AS#1
CLS
INPUT "Enter name";N
INPUT "Enter age";A
WRITE 1,N$,A
CLOSE #1
END
19. [PABSON 2079
C]
REM to store record in data file
CLS
OPEN "employee.dat" FOR INPUT AS #1
DO
INPUT "Enter Name, address and gender": N$, A, G
INPUT #1, N$, A. G
INPUT "Do you want to continue "; Y$
WHILE UCASE$(Y$) = "Y"
CLOSE "employee.dat"
END
20. [PABSON 2079
D]
REM to create sequential data file "record.dat" to
enter some records.
CLS
OPEN "record.dat" FOR INPUT AS #1
UP:
INPUT "ENTER NAME";N$
INPUT "ENTER ADDRESS";A$
INPUT "ENTER PHONE NUMBER";PH
WRITE #2, N$,A$,PH
INPUT "Do you want to continue(y/n)?";an
IF LCASE(an$)="y" THEN GOTO UP
CLOSE #1
END
21. [PABSON 2079
PQ]
REM to store name, address in the file "store.dat"
CLS
OPEN "store.dat" FOR INPUT AS #1
DO
INPUT "Enter name"; name$
INPUT "Enter address"; address
WRITE name$, address$
INPUT "do you want to continue"; ans$
LOOP WHILE UCASE$(ans$)="Y"
CLOSE #2
END
22. [PABSON 2079
MT]
REM to display the reverse of the supplied string
DECLARE SUB rev (s$)
CLS
INPUT n$
CALL rev$(n$)
END
SUB rev (n$)
FOR k=1 TO LEN(n$).
a$ = MID$(n$, 1, k)
p$ = p$ + n$
NEXT k
PRINT p$
END SUB
23. [PABSON 2079
FT]
DECLARE SUB SUM
(P, Q, R)
CLS
INPUT “Enter the
numbers”: P,Q,R
CALL SUM
END SUB
SUB Check(P,Q,R)
S = P + Q + R
PRINT “Sum of
three numbers is”; SUM
END SUB
24. [PABSON PB
2078]
REM to
add more data in a sequential file.
OPEN
“EMP.DAT” FOR INPUT AS #2
DO
INPUT
“ENTER NAME”; N$
INPUT
“ENTER ADDRESS”; A$
INPUT
“ENTER SALARY”; S$
WRITE
#1, N$, A$, S
INPUT” Do you want
to add more records.”; M$
LOOP WHILE
UCASE(M$) = “Y”
END
25.[SEE PB 2077]
REM to count total
no. of passed student
CLS
WHILE NOT EOF ( )
OPEN “I”, #1,
RESULT.DAT
INPUT #1, ID, M1,
M2, M3
IF M1>=32,
M2>=32, M3>=32 THEN
X=X+1
END IF
WEND
PRINT “TOTAL
RECORD”; X
END
26. [SLC 2065]
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
27. [SLC 2066]
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
28. [SLC 2067]
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
29. [SLC 2069]
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
30. [SLC 2070]
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()
31. [SLC 2071]
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
32. [SLC 2072]
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
33. [SLC 2065 S]
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()
34. [SLC 2066 S]
OPEN EMP.DOC FOR OUTAS#1
INPUT “Enter Name”; N
INPUT “Enter post”; P$
INPUT “Enter salary”; S
WRITE #2, N$,P$,S
CLOSE #1
END
35. [SLC 2067 S]
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()
36. [SLC 2068 S]
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
37. [SLC 2069 S]
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
38. [SLC 2070 S]
OPEN
"STUDENT.DAT" FOR APPEND AS 1#
INPUT "NAME"; N$
INPUT "ADDRESS"; ADD$
INPUT "AGE"; AGE$
WRITE #1, N$, ADD$, AGE
END# 1
STOP
39. [SLC 2071 S]
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
40. [SLC 2073]
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
41. [SLC 2074]
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
42. [SEE 2073 U]
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
43. [SEE 2074 U]
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
44. [SEE 2075]
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
45. [SEE 2075 U]
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
46. [SEDIPS 2081]
REM to count total number of values
existing among a different number input by a user DIVISIBLE BY 3.
DECLARE FUNCTION DIVBY3 (a( ), n)
CLS
FOR CNT=0 TO n-1
INPUT "Enter the number";
a(n)
NEXT CNT
Totno=DIVBY3 (a, n)
PRINT "Total number of values
divisible by 3 is"; totno
END
FUNCTION DIVBY3( )
count=0
FOR CNT=0 to n-1
IF a(CNT) MOD 3=0 THEN
count=count+1
NEXT CNT
COUNT=DIVBY3
END FUNCTION
47. [SEDIPS 2080]
REM to
calculate the sum of even numbers existing in the set of given numbers.
DECLARE
FUNCTION evenpro(A)
FOR C=1 TO
5
READ N
S=S+evenpro(A)
NEXT C
PRINT Ssum
of even numbers:"; S
DATA 1, 2,
3, 4, 5, 6, 7, 8, 9, 10
END
FUNCTION
evenpro(A)
R=A MOD 2
IF R<
>0 THEN
A=evenpro
ENDIF
END
FUNCTION
48. [SEDIPS 2079]
DECLARE FUNCTION vowel(S$)
w$=we love our country
v=vowel(w$)
PRINT "The total no.
of vowel::"; v
END
FUNCTION vowel$(S$)
c=0
FOR K=1 TO length(S$)
B$=MID$(S$, K, 1)
B$=LCASE$(B$)
SELECT CASE B$
CASE "a",
"e", "i", "o", "u"
c=c+1
END SELECT
NEXT K
C=vowel
END FUNCTION
49. [NPABSAN 2081]
DECLARE FUNCTION SQ$ (N)
CLS
FOR I=1 TO 10
DISPLAY SQ (N)
NEXT N
END
FUNCTION SQ (N)
SQ=N^2
END FUNNCTION
50. [NPABSAN 2080]
REM Program to add
records to an existing file "Student.dat"
OPEN
"Student.dat" FOR APPEND AS #1
DO
CLS
INPUT "Enter
name: "; N$
INPUT "Enter
Address: "; Ad$
INPUT "Enter Total
Marks: "; TM$
COPY #1, N$, Ad$, TM
INPUT "Do you
want to add more records? Press Y or N: "; CH$
LOOP WHILE
UCASE$(CH$) < > “Y”
CLOSE
"Student.dat"
END
51. [NPABSAN 2080 A]
DECLARE SUB great(p,q)
CLS
INPUT "Any two numbers”; a, b
DISPLAY great (p, q)
END
SUB great (p, q)
IF a < b THEN
PRINT p;
ELSE
PRINT q;
END
END SUB
52. [NPABSAN 2079]
DECLARE SUB sbn()
CLS
CALL SUB sbn (14)
END SUB
SUB sbn()
INPUT "enter the
variable value”; var
PRINT "Square of given
number"; var^2
END
53. [NPABSAN 2078]
DECLARE FUNCTION PAL$ (W$)
CLS
INPUT "Enter a word"; W$
SHOW PAL$ (W$)
END
FUNCTION PAL$ (W$)
FOR I= LEN (W$) TO 1 STEP1
R$=R$+MID$ (W$, I, 1)
NECT I
IF R$-W$ THEM
P$="Palindrome"
ELSE
P$="Not palindrome"
ENDIF
P$=PAL$
54. [PABSON 2081 K]
REM TO CHECK ODD OR EVEN NUMBERS.
DECLARE FUNCTION TEST$(N)
CLS
INPUT “ENTER ANY NUMBER”; N$
PRINT “THE NUMBER IS “; TEST$
END
FUNCTION TEST$(N)
R = R MOD 2
IF R = 0 THEN
A$= “EVEN”
ELSE
A$ = “ODD”
END IF
A$ = TEST$
END FUNCTION
55. [PABSON 2081 L]
REM To copy all data from
sequential data file INFO.DAT to NEWINFO.DAT.
OPEN "INFO.DAT" FOR INPUT
AS #1
OPEN "NEWINFO.DAT" FOR
INPUT AS #2
DO WHILE NOT EOF(1)
LINE INPUT #1, ALL$
COPY #2, ALL$
WEND
FINISH #1,#2
END