QBasic is also a Modular Programming Language because it allows users to work on different Blocks. Here we have given you solutions for some QBasic Programs. We hope it helps you clearing your doubts.

# Write a program to calculate the volume of a cylinder using FUNCTION ………. END FUNCTION. [Hint : PI * R ^ 2 * H]

Program :

DECLARE FUNCTION VOL (R, H)

CLS

CONST PI = 3.14

INPUT “Enter Radius of the Cylinder”; R

INPUT “Enter Height of the Cylinder”; H

PRINT “The volume of the cylinder is”; VOL (R, H)

END

FUNCTION VOL (R, H)

V = PI * R ^ 2 * H

VOL = V

END FUNCTION

# Write a program to test whether the given number is positive or negative using SUB ………. END SUB.

Program :

DECLARE NUMTEST (N)

CLS

INPUT “Enter a number”; N

CALL TEST (N)

END

SUB TEST (N)

IF N > 0 THEN

PRINT “The given number” N; “is a positive number”

ELSE

PRINT “The given number” N; “is a negative number”

END IF

END SUB

# Write a program to print the following series : 1,4,7, ………. up to 10^{th} term using FUNCTION ………. END FUNCTION.

Program :

DECLARE FUNCTION SERIES ()

CLS

D = SERIES

END

FUNCTION SERIES

A = 1

FOR I = 1 TO 10

PRINT A;

A = A + 3

NEXT I

END FUNCTION

# Write a program which accepts any three different numbers and find the maximum number among them using the CALL statement.

Program :

DECLARE SUB MAX (A, B, C)

CLS

INPUT “Enter the First number”; A

INPUT “Enter the Second number”; B

INPUT “Enter the Third number”; C

CALL MAX (A, B, C)

END

SUB MAX (A, B, C)

IF A > B AND A > C THEN

PRINT A; “is maximum number”

ELSEIF B > A AND B > C THEN

PRINT B; “is the maximum number”

ELSE

PRINT C; “is the maximum number”

END IF

END SUB

# Write a program to display greater number among any two numbers using FUNCTION ………. END FUNCTION.

Program :

DECLARE FUNCTION GRE (A, B)

CLS

INPUT “Enter the First number”; A

INPUT “Enter the Second number”; B

PRINT “The Greater Number is”; GRE (A, B)

END

FUNCTION GRE (A, B)

IF A > B THEN

GRE = A

ELSE

GRE = B

END IF

END FUNCTION

# Write a program to print the following series: 1, 8, 27, 64, ………. up to 10^{th} terms using SUB procedure

Program :

DECLARE SUB SERIES ()

CLS

CALL SERIES

END

SUB SERIES

FOR I = 1 TO 10

PRINT I ^ 3;

NEXT I

END SUB

# Write a program to find the factorial number of any non-negative number using FUNCTION ………. END FUNCTION.

Program :

DECLARE FUNCTION FACT (N)

CLS

INPUT “Enter a non-negative number”; N

PRINT “The factorial of given number is”; FACT (N)

END

FUNCTION FACT (N)

F = 1

FOR I = 1 TO N

F = F * I

NEXT I

FACT = F

END FUNCTION

# Write a program to display the series 55555, 5555, 555, 55, 5 using SUB ………. END SUB.

Program :

DECLARE SUB SERIES ()

CLS

CALL SERIES

END

SUB SERIES

A = 55555

FOR I = 1 TO 5

PRINT A;

A = A \ 10

NEXT I

END SUB

# Write a program to display vowels and consonants of the entered string by using FUNCTION ………. END FUNCTION.

Program :

DECLARE FUNCTION STR (S$)

CLS

INPUT “Enter a word”; S$

WORD = STR(S$)

END

FUNCTION STR (S$)

FOR I = 1 TO LEN(S$)

B$ = MID$(S$, I, 1)

W$ = UCASE$(B$)

IF W$ = “A” OR W$ = “E” OR W$ = “I” OR W$ = “O” OR W$ = “U” THEN

V$ = V$ + ” ” + B$

ELSE C$ = C$ + ” ” + B$

END IF

NEXT

PRINT “The vowels are”; V$

PRINT “The consonants are”; C$

END FUNCTION

# Write a program to display the reverse of the entered number.

Program (Using SUB Procedure) :

DECLARE SUB REV (N)

CLS

INPUT “Enter a number”; N

CALL REV (N)

END

SUB REV (N)

S=0

WHILE N <> 0

R = N MOD 10

S = S * 10 + R

N = N \ 10

WEND

PRINT “The reversed form is”; S

END SUB

Program (Using FUNCTION Procedure) :

DECLARE FUNCTION REV (N)

CLS

INPUT “Enter a number”; N

PRINT “The reversed form is”; REV (N)

END

FUNCTION REV (N)

S = 0

WHILE N <> 0

R = N MOD 10

S = S * 10 + R

N = N \ 10

WEND

REV = S

END FUNCTION

# Write a program to declare a SUB procedure module to generate multiplication table of any non-negative number, where number is passed as a parameter by using SUB ………. END SUB Statement. (Upto 10)

Program :

DECLARE SUB MULT (N)

CLS

INPUT “Enter a number”; N

CALL MULT (N)

END

SUB MULT (N)

FOR I = 1 TO 10

PRINT N; “*”; I; “=”; N*I

NEXT I

END SUB

# Write a program to define a function procedure to display area of sphere where user has to input the required data in the main module. [Hint: Area of Sphere : 4*PI*R^2]

Program :

DECLARE FUNCTION AREA (R)

CLS

CONST PI = 3.14

INPUT “Enter radius”; R

PRINT “The Area of Sphere =”; AREA (R)

END

FUNCTION AREA (R)

A = 4 * PI * R ^ 2

AREA = A

END FUNCTION

# Write a program to define SUB procedure to display the following series of number: 1, 1, 2, 3, 5, ………. up to 13^{th}term.

Program :

DECLARE SUB SERIES ()

CLS

CALL SERIES

END

SUB SERIES

A = 1

B = 1

PRINT A; B;

FOR I = 1 TO 11

C = A + B

PRINT C;

A = A + B

B = A – B

NEXT I

END SUB

# Using user defined function, write a program to input monthly income in parameter then computer annual tax to be paid. The tax rate is 15% if annual income is above Rs. 200000, otherwise tax rate is 1%.

Program :

DECLARE FUNCTION TAX (I)

CLS

INPUT “Enter your Monthly Income”; I

PRINT “The Annual Tax to be paid is Rs.”; TAX(I)

END

FUNCTION TAX (I)

A = I * 12

IF A > 200000 THEN

TAX = 15 / 100 * A

ELSE

TAX = 1 / 100 * A

END IF

END FUNCTION

# Write a program to generate the series using SUB ………. END SUB : -10, -8, -6, -4, ………. Up to 20^{th} term.

Program :

DECLARE SUB SERIES ()

CLS

CALL SERIES

END

SUB SERIES

A = -10

FOR I = 1 TO 20

PRINT A;

A = A + 2

NEXT I

END SUB

# Write a program using FUNCTION ………. END FUNCTION to calculate and print the total surface area of a sphere.

Program :

DECLARE FUNCTION TSA (R)

CLS

CONST PI = 3.14

INPUT “Enter the Radius of the Sphere”; R

PRINT “The Total Surface Area (T.S.A) of the Sphere is”; TSA (R)

END

FUNCTION TSA (R)

T = 4 * PI * R ^ 2

TSA = T

END FUNCTION

# Write a program to Declare SUB Procedure to print only the vowels from a given word.

Program :

DECLARE SUB VOWELS (V$)

CLS

INPUT “Enter a word”; V$

CALL VOWELS (V$)

END

SUB VOWELS (V$)

PRINT “The vowel letters are”

FOR I = 1 TO LEN(V$)

A$ = MID$(V$,I,1)

B$ = UCASE$(A$)

IF B$ = “A” OR B$ = “E” OR B$ = “I” OR B$ = “O” OR B$ = “U” THEN PRINT A$

NEXT I

END SUB

# Write a program that asks any number and calculates its factors using a SUB procedure.

Program :

DECLARE SUB FACT (N)

CLS

INPUT “Enter a number”; N

CALL FACT (N)

END

SUB FACT (N)

PRINT “The factors of”; N; “are”

FOR I = 1 TO N

IF N MOD I = 0 THEN PRINT I

NEXT I

END SUB

# Write a program to find the sum of factors of input number using SUB Procedure.

Program :

DECLARE SUB FACT(N)

CLS

INPUT “Enter a Number”; N

CALL FACT(N)

END

SUB FACT(N)

FOR I = 1 TO N

IF N MOD I = 0 THEN S=S+I

NEXT I

PRINT “SUM OF FACTORS” ; S

END SUB

# Write a program that asks any three numbers and displays the difference between the greatest and the smallest value among the 3 supplied numbers using FUNCTION procedure.

Program :

DECLARE FUNCTION DIFF (A, B, C)

CLS

INPUT “Enter the First Number”; A

INPUT “Enter the Second Number”; B

INPUT “Enter the Third Number”; C

PRINT “The Difference between the Greatest and Smallest Number is”; DIFF (A, B, C)

END

FUNCTION DIFF (A, B, C)

G = 0

S = 0

IF A > B AND A > B THEN

G = A

ELSEIF B > A AND B > C THEN

G = B

ELSE

G = C

END IF

IF A < B AND A < C THEN

S = A

ELSEIF B < A AND B < C THEN

S = B

ELSE

S = C

END IF

DIFF = G – S

END FUNCTION

# Check input number is prime or not using SUB Procedure.

Program :

DECLARE SUB PRIME(A)

CLS

INPUT “Enter a Number” ; A

CALL PRIME (A)

END

SUB PRIME (A)

FOR I = 1 TO A

IF A MOD I = 0 THEN C = C + 1

NEXT I

IF C = 2 THEN

PRINT “The given number is a Prime Number”

ELSE

PRINT “The given number is a not Prime Number”

ENDIF

END SUB

# Display prime numbers from 1 to 500 using SUB Procedure.

Program :

DECLARE SUB PRIME ()

CLS

CALL PRIME

END

SUB PRIME

FOR I = 1 TO 500

C = 0

FOR J = 1 TO I

IF I MOD J = 0 THEN C = C + 1

NEXT J

IF C = 2 THEN PRINT I

NEXT I

END SUB