DOWNLOADED FROM SUSHILUPRETI.COM.NP
1a) Write down the different types of operators with examples.
b) Write the output of the following program
FOR I= 1 TO 4
S=1
FOR J=1 TO 3
T = I * J
PRINT T;
IF T/2 = T\2 THEN S=S+T
NEXT
PRINT S
NEXT
c) Re-write the following program using DO……LOOP UNITL.
INPUT A
I = 2
F = A – 1
FOR X = F TO 1 STEP-1
IF A MOD X = 1 THEN
C = C + 1
END IF
NEXT X
IF C < > 0 THEN PRINT A
END
d) Re-write the following program correcting the bugs:
REM TO PRINT THE LONGEST STRING
DIM A$(5)
FOR I = 1 TO 5
READ A$(X)
DATA ADDICTION, CLEANSE, EFFECT, LOOK
DATA FURTHER, INTERNATIONAL
X = LEN(A$(I))
IF X > LNG THEN
LNG = X
S$ = A$
END IF
NEXT J
PRINT “THE LONGEST STRING IS:”;LEN(S$)
END
e) Wap to check whether the supplied word is palindrome or not using function procedure.
f) A sequential data file “INFO.INF” has 4000 records. Write a program to display its first 50 records.
Answers SET U
1a)
The different types of operators with examples are as follows:
i) Arithmetic operators - +, -, *, /, \, ^, MOD
ii) Relational operators - =, < >, <, >, <=, >=
iii) Logical operators – AND, OR, NOT
iv) String operator - +
b) Output
1 2 3 3
2 4 6 13
3 6 9 7
4 8 12 25
c) program using DO……LOOP UNITL.
INPUT A
I = 2
F = A - 1
X = F
DO
IF A MOD X = 1 THEN
C = C + 1
END IF
X = X - 1
LOOP UNTIL X > 1
IF C <> 0 THEN PRINT A
END
d) Debugged Program
REM TO PRINT THE LONGEST STRING
DIM A$(5)
FOR I = 1 TO 5
READ A$(I)
DATA ADDICTION, CLEANSE, EFFECT, LOOK
DATA FURTHER, INTERNATIONAL
X = LEN(A$(I))
IF X > LNG THEN
LNG = X
S$ = A$(I)
END IF
NEXT I
PRINT "THE LONGEST STRING IS:"; S$
END
e) Wap to check whether the supplied word is palindrome or not using function procedure.
DECLARE FUNCTION REV$ (S$)
CLS
INPUT "ENTER ANY WORD"; S$
C$ = REV$(S$)
IF S$ = C$ THEN
PRINT S$; “IS PALINDROME”
ELSE
PRINT S$; “IS NOT PALINDROME”
END IF
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
f) A sequential data file “INFO.INF” has 4000 records. Write a program to display its first 50 records.
OPEN "INFO.INF" FOR INPUT AS #1
CLS
FOR I = 1 TO 4000
LINE INPUT #1, R$
D = D + 1
IF D >= 1 AND D <= 10 THEN PRINT R$
NEXT I
CLOSE #1
END
***
SOURCE : WWW.SUSHILUPRETI.COM.NP
1a) Differentiate between INT( ) and FIX ( ) functions.
b) Write the output of the following program
CLS
X = 127
DO
S = X MOD 3 + 5
IF S MOD 3 = 0 THEN GOTO AA
PRINT S;
AA:
X = X - 10
LOOP WHILE X >= 45
END
c) Re-write the following program using WHILE ….WEND as inner loop and DO……LOOP UNITL as outer loop.
CLS
FOR I = 10 TO 40 STEP 5
FOR J = 2 TO I - 1
IF I MOD J = 0 THEN
PRINT I
GOTO BB
END IF
NEXT J
BB:
NEXT I
END
d) Re-write the following program correcting the bugs:
REM display the greatest number among 10
CLS
DIM A(12)
FOR X = 1 TO 10
READ J(X)
NEXT X
FOR J = 1 TO 9
IF MAX < A(X) THEN
A(J) = MAX
END IF
NEXT J
PRINT "MAX"
DATA 10, 23, 33, 44, 33, 55, 16, 23, 22, 21
END
e) Write a program that asks your name and displays only the consonant sounds present in the supplied name using:
i) FUNCTION…..END FUNCTION
ii) SUB….END SUB
Answers
1a) The difference between INT ( ) and FIX ( ) functions is INT () returns the largest integer less than or equal to a numeric expression whereas FIX truncates a floating-point expression to its integer portion.
Eg.
PRINT INT(2.2) = 2
PRINT INT (-2.2) = 3
PRINT INT (2.8) = 2
PRINT INT (-2.8) = 3
PRINT FIX(2.2) = 2
PRINT FIX (-2.2) = 2
PRINT FIX (2.8) = 2
PRINT FIX (-2.8) = 2
b) Output
5 7 5 7 5 7
c) program using WHILE ….WEND as inner loop and DO……LOOP UNITL as outer loop.
CLS
I = 10
DO
J = 2
WHILE J <= I - 1
IF I MOD J = 0 THEN
PRINT I
GOTO BB
END IF
J = J + 1
WEND
BB:
I = I + 5
LOOP UNTIL I > 40
END
d) Debugged Program
REM display the greatest number among 10
CLS
DIM A(10)
FOR X = 1 TO 10
READ A(X)
NEXT X
MAX = A(1)
FOR J = 2 TO 10
IF A(J) > MAX THEN
MAX = A(J)
END IF
NEXT J
PRINT MAX
DATA 10, 23, 33, 44, 33, 55, 16, 23, 22, 21
END
e) Write a program that asks your name and displays only the consonant sounds present in the supplied name using:
i) FUNCTION…..END FUNCTION
ii) SUB….END SUB
i) FUNCTION…..END FUNCTION
DECLARE FUNCTION DISPLAY (A$)
CLS
INPUT "ENTER YOUR NAME"; A$
D = DISPLAY(A$)
END
FUNCTION DISPLAY (A$)
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ <> "A" AND C$ <> "E" AND C$ <> "I" AND C$ <> "O" AND C$ <> "U" THEN
PRINT B$;
END IF
NEXT I
END FUNCTION
ii) SUB….END SUB
DECLARE SUB DISPLAY (A$)
CLS
INPUT "ENTER YOUR NAME"; A$
CALL DISPLAY(A$)
END
FUNCTION DISPLAY (A$)
FOR I = 1 TO LEN(A$)
B$ = MID$(A$, I, 1)
C$ = UCASE$(B$)
IF C$ <> "A" AND C$ <> "E" AND C$ <> "I" AND C$ <> "O" AND C$ <> "U" THEN
PRINT B$;
END IF
NEXT I
END FUNCTION
***
No comments:
Post a Comment