DOWNLOADED FROM SUSHILUPRETI.COM.NP
1a) Write down the truth table of OR operator.
b) Write down the output of the following program.
DECLARE SUB ABC (N)
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
c) Re-write the following program correcting the bugs:
REM to count length of a string
DECLARE FUNCTION length (n$)
CLS
INPUT "Type any string"; s$
PRINT "length of the string"; length(n$)
END
FUNCTION length (a$)
b = 1
aa:
c$ = MID$(a$, 1, b)
IF c$ = "" THEN
b = b + 1
x = x + 1
GOTO aa
END IF
length = b
END FUNCTION
d) Write a program to find the sum of the range of numbers supplied by the user (The first and the last number of the natural number should be supplied by the user) using
i) FUNCTION …..END FUNCTION
ii) SUB…END SUB
Answers SET O
1a) Truth Table of OR operator
Condition 1
|
Condition 2
|
Result
|
True
|
True
|
True
|
True
|
False
|
True
|
False
|
True
|
True
|
False
|
False
|
False
|
b) Output
24
48
12
c) Debugged Program
REM to count length of a string.
DECLARE FUNCTION length (n$)
CLS
INPUT "type of string"; s$
PRINT "length of the string"; length(s$)
END
FUNCTION length (a$)
b = 1
aa:
c$ = MID$(a$, b, 1)
IF c$ <> "" THEN
b = b + 1
x = x + 1
GOTO aa
END IF
length = x
END FUNCTION
d) Write a program to find the sum of the range of numbers supplied by the user (The first and the last number of the natural number should be supplied by the user) using
i) FUNCTION …..END FUNCTION
DECLARE FUNCTION sum (a, b)
CLS
INPUT "enter first number"; a
INPUT "enter the final number"; b
PRINT "sum of natural numbers="; sum(a, b)
END
FUNCTION sum (a, b)
FOR i = a TO b
s = s + i
NEXT
sum = s
END FUNCTION
ii) SUB…END SUB
DECLARE SUB sum (a, b)
CLS
INPUT "enter first number"; a
INPUT "enter the final number"; b
CALL sum(a, b)
END
SUB sum (a, b)
FOR i = a TO b
s = s + i
NEXT
PRINT "sum of natural numbers="; s
END SUB
***
DOWNLOADED FROM SUSHILUPRETI.COM.NP
1a) Write down the use and syntax of MID$ function.
b) Write down the output of the following program.
I = 1
DO UNTIL I >5
J = 1
WHILE J< =I
PRINT J;
J=J+1
WEND
I=I+1
PRINT
LOOP
END
c) Re-write the following program correcting the bugs:
REM Program to find the sum of even digits of a supplied number
INPUT “ENTER NUMBER”; N$
S = ZERO
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 1 THEN S = S + R
N = INT(N/10)
LOOP
PRINT “Sum of even digits = “;r
END
d) Re-write the following program using SELECT……CASE STATEMENT.
INPUT “ENTER PERCENTAGE”; P
IF P>=60 THEN
PRINT “FIRST DIVISION”
ELSEIF P>=45 AND P<=59 THEN
PRINT “SECOND DIVISION”
ELSEIF P>=40 AND P<=44 THEN
PRINT “THIRD DIVISION”
ELSE
PRINT “FAIL”
END IF
END
e) Write a program to supply a string and print the string in reverse form using FUNCTION..END FUNCTION
Answers SET P
1a) Syntax and Function of MID$ function
Syntax: MID$(stringexpression$, start%[,length%])
Function : returns part of a string (a substring).
b) Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
c) Debugged Program
REM Program to find the sum of even digits of a supplied number
INPUT “ENTER NUMBER”; N
S = 0
WHILE N<>0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R
N = INT(N/10)
WEND
PRINT “Sum of even digits = “;S
END
d) program using SELECT……CASE STATEMENT
INPUT “ENTER PERCENTAGE”; P
SELECT CASE P
CASE IS>=60
PRINT “FIRST DIVISION”
CASE 45 TO 59
PRINT “SECOND DIVISION”
CASE 40 TO 44
PRINT “THIRD DIVISION”
CASE ELSE
PRINT “FAIL”
END SELECT
END
e) Write a program to supply a string and print the string in reverse form using FUNCTION..END FUNCTION
DECLARE FUNCTION REV$ (S$)
CLS
INPUT "ENTER ANY STRING"; S$
PRINT "REVERSED STRING IS "; REV$(S$)
END
FUNCTION REV$ (S$)
FOR I = LEN(S$) TO 1 STEP -1
B$ = MID$(S$, I, 1)
W$ = W$ + B$
NEXT I
REV$ = W$
END FUNCTION
***
No comments:
Post a Comment