QBASIC PROGRAMS For SEE Appearing Students – SET 2

Print This Page

Questions are taken from Brush-up Computer Science  Book  [Benchmark Publication ]

1. Write a program to find area of four walls.

Using Function Procedure: 

DECLARE FUNCTION AREA(L,B,H)

CLS

INPUT “ENTER LENGTH” ; L

INPUT “ENTER BREADTH” ; B

INPUT “ENTER HEIGHT” ; H

PRINT “THE AREA OF FOUR WALLS= ” ; AREA(L,B,H)

END

FUNCTION AREA(L,B,H)

AREA=2*H*(L+B)

END FUNCTION

Using SUB Procedure

DECLARE SUB AREA(L,B,H)

CLS

INPUT “ENTER LENGTH” ; L

INPUT “ENTER BREADTH” ; B

INPUT “ENTER HEIGHT” ; H

CALL  AREA(L,B,H)

END

SUB AREA(L,B,H)

A=2*H*(L+B)

PRINT “AREA IS “; A

END FUNCTION

 

2. Write a program to define a function procedure that returns simple interest.

Using FUNCTION Procedure : 

DECLARE FUNCTION SI(P,T,R)

CLS

INPUT “ENTER PRINCIPLE” ; P

INPUT “ENTER TIME” ; T

INPUT “ENTER RATE” ; R

PRINT “SIMPLE INTEREST IS = ” ;SI(P,T,R)

END

FUNCTION SI(P,T,R)

SI=(P*T*R)/100

END FUNCTION

Using SUB Procedure :

DECLARE SUB SI(P,T,R)

CLS

INPUT “ENTER PRINCIPLE” ; P

INPUT “ENTER TIME” ; T

INPUT “ENTER RATE” ; R

CALL SI(P,T,R)

END

SUB SI(P,T,R)

I=(P*T*R)/100

PRINT “INTEREST IS ” ; I

END SUB

3. Write a program to convert the supplied Nepalese currency into its equivalent Indian currency.

 

Using FUNCTION Procedure :

DECLARE FUNCTION CONV(N)

CLS

INPUT “ENTER NEPALESE CURRENCY ” ; P

PRINT “INDIAN CURRRENCY = ” ;CONV(P)

END

FUNCTION CONV(P)

CONV=P/1.6

END FUNCTION

Using SUB Procedure:

DECLARE SUB CONV(N)

CLS

INPUT “ENTER NEPALESE CURRENCY ” ; P

CALL CONV(P)

END

SUB CONV(P)

C=P/1.6

PRINT “INDIAN CURRENCY “; C

END SUB

4. Write a program  to check whether an input number is even or odd.

Using Function Procedure:

DECLARE FUNCTION CONV$(N)

CLS

INPUT “ENTER  A NUMBER ” ; P

PRINT CONV$(P)

END

FUNCTION CONV$(P)

IF P MOD 2 = 0 THEN

CONV$=”EVEN NUMBER”

ELSE

CONV$=”ODD NUMBER”

ENDIF

END FUNCTION

Using SUB Procedure:

DECLARE SUB CONV(P)

CLS

INPUT “ENTER  A NUMBER ” ; P

CALL CONV(P)

END

SUB CONV(P)

IF P MOD 2 = 0 THEN

PRINT “EVEN NUMBER”

ELSE

PRINT “ODD NUMBER”

ENDIF

END SUB

 

5. Write a program to check whether the input number is divisible by 4 and  6  or not.

Using Function Procedure:

DECLARE FUNCTION CHECK$(N)

CLS

INPUT “ENTER  A NUMBER ” ; P

PRINT CHECK$(P)

END

FUNCTION CHECK$(P)

IF P MOD 4 =0 AND P MOD 6=0 THEN

CHECK$=”DIVISIBLE BY BOTH NUMBERS”

ELSE

CONV$=”NOT DIVISIBLE BY BOTH NUMBERS”

ENDIF

END FUNCTION

Using Sub Procedure: 

DECLARE SUB CHECK(N)

CLS

INPUT “ENTER  A NUMBER ” ; P

CALL  CHECK(P)

END

SUB CHECK(P)

IF P MOD 4 =0 AND P MOD 6=0 THEN

PRINT “DIVISIBLE BY BOTH NUMBERS”

ELSE

PRINT “NOT DIVISIBLE BY BOTH NUMBERS”

ENDIF

END SUB

6. Write a program  to calculate the square of all digits of input number.

Using Function Procedure:

DECLARE FUNCTION SQU(A)

CLS

INPUT “ENTER A NUMBER” ; N

PRINT SQU(N)

FUNCTION SQU(N)

WHILE N<>0

R=N MOD 10

S=R^2

PRINT   S

N=N\10

WEND

END DUNCTION

Using Sub Procedure :

DECLARE SUB SQU(A)

CLS

INPUT “ENTER A NUMBER” ; N

CALL SQU(N)

END

SUB SQU(N)

WHILE N<>0

R=N MOD 10

S=R^2

PRINT   S

N=N\10

WEND

END SUB

7. Write a program to calculate the circumference of circle.

Using Function Procedure:

DECLARE FUNCTION CIR(A)

CLS

INPUT “ENTER RADIUS OF A CIRCLE”; R

PRINT “CIRCUMFERENCE IS” ; CIR(R)

END

FUNCTION CIR(A)

P=3.14

CIR=2*P*A

END FUNCTION

Using SUB Procedure:

DECLARE SUB CIR(A)

CLS

INPUT “ENTER RADIUS OF A CIRCLE”; R

CALL CIR(R)

END

SUB CIR(A)

P=3.14

C=2*P*A

PRINT “CIRCUMFERENCE IS ” ; C

END SUB

8. Write a program to display the reverse of input string .

Using Function Procedure

DECLARE FUNCTION REV$(N$)

CLS

INPUT “ENTER A STRING” ; W$

PRINT  “REVERSED STRING::”;REV$(W$)

END

FUNCTION REV$(N$)

FOR I = LEN(N$) TO 1 STEP -1

D$=D$+MID$(N$,I,1)

NEXT I

REV$=D$

END FUNCTION

Using SUB Procedure:

DECLARE SUB REV(N$)

CLS
INPUT “ENTER A WORD” ; W$

CALL REV(W$)

END

SUB REV(N$)
FOR I = LEN(N$) TO 1 STEP-1
C$=C$+MID$(N$,I,1)

NEXT I

PRINT “REVERSED STRING” ; C$

END SUB

9. Write a program that accepts three different numbers and returns the smallest one.

Using Function Procedure:

DECLARE FUNCTION SMALL(A,B,C)

CLS

INPUT “ENTER FIRST NUBER” ; A

INPUT “ENTER SECOND NUMBER” ; B

INPUT “ENTER THIRD NUMBER” ; C

PRINT “THE SMALLEST NUMBER IS” ; SMALL(A,B,C)

FUNCTION SMALL(A,B,C)

IF A<B AND B<C THEN

SMALL=A

ELSE IF B<A AND A<C THEN 

SMALL=B

ELSE

SMALL=C

END FUNCTION

Using SUB Procedure:

DECLARE SUB SMALL(A,B,C)

CLS

INPUT “ENTER FIRST NUBER” ; A

INPUT “ENTER SECOND NUMBER” ; B

INPUT “ENTER THIRD NUMBER” ; C

CALL SMALL(A,B,C)

FUNCTION SMALL(A,B,C)

IF A<B AND B<C THEN

PRINT “SMALLEST” ; A

ELSE IF B<A AND A<C THEN

PRINT “SMALLEST” ; B

ELSE

PRINT “SMALLEST” ; C

END SUB

10. WAP to find whether the first character of the input string is a number, an uppercase or lowercase character or none of them.

 

Using Function Procedure:

DECLARE FUNCTION CHTR$(A$)

CLS

INPUT “ENTER A STRING” ; C$

PRINT CHTR$(C$)

END

FUNCTION CHTR$(A$)

D$=LEFT$(A$)

A=ASC(D$)

IF A>=65 AND A<=90 THEN

CHTR$=”FIRST LETTERIS UPPERCASE LETTER”

ELSEIF A>=97 AND A<=122 THEN

CHTR$=”FIRST LETTER IS LOWERCASE”

ELSEIF A>=48 AND A<=57 THEN

CHTR$=”FIRST LETTER IS NUMBER”

ELSE

CHTR$=”NONE OF THEM”

END FUNCTION

Using SUB Procedure:

DECLARE SUB CHTR(A$)

CLS

INPUT “ENTER A STRING” ; C$

CALL CHTR(C$)

END

SUB CHTR(A$)

D$=LEFT$(A$)

A=ASC(D$)

IF A>=65 AND A<=90 THEN

PRINT “FIRST LETTER IS UPPERCASE LETTER”

ELSEIF A>=97 AND A<=122 THEN

PRINT “FIRST LETTER IS LOWERCASE”

ELSEIF A>=48 AND A<=57 THEN

PRINT “FIRST LETTER IS NUMBER”

ELSE

PRINT “NONE OF THEM”

END SUB

————————————-THANK YOU—————————————–

IF YOU HAVE ANY QUERIES COMMENT BELOW

Leave a Reply