(X) QBASIC LAB TIME

Book Page 178 A. Write a program with sub procedure to input length,breadth and height. Then, calculate the area of four walls where A=2*H(L+B). Answer: DECLARE SUB AREA(L,B,H) INPUT "Enter length, breadth and height : ";L,B,H CALL AREA(L,B,H) END SUB AREA (L,B,H) A = 2 * H * (L + B) PRINT " Area of four wall : ";A END SUB B. Write a program with sub procedure to find the volume of box where V=LxBxH. Answer: DECLARE SUB VOLUME(L,B,H) INPUT "Enter length, breadth and height : ";L,B,H CALL VOLUME(L,B,H) END SUB VOLUME (L,B,H) V = L * B * H PRINT " Volume of a box : ";V END SUB C. Write a program to input two different numbers in the main module then print the greater number using sub procedure. Answer: DECLARE SUB CHECK(A,B) INPUT "Enter two numbers : ", A,B CALL CHECK(A,B) END SUB CHECK(A,B) IF A>B THEN PRINT A;" is greater" ELSE PRINT B; " is greater" END IF END SUB Book Page 179 A. Write a program to input a number and print the multiplication table using Sub. Answer: DECLARE SUB MTABLE(N) INPUT "Enter any number : ", N CALL MTABLE(N) END SUB MTABLE(N) FOR I = 1 TO 10 PRINT N * I NEXT I END SUB B. Write a progran to input three different numbers in the main module and then print the average using a sub-procedure. Answer: DECLARE SUB AVERAGE(A,B,C) INPUT "Enter three numbers : ", A,B,C CALL AVERAGE(A,B,C) END SUB AVERAGE(A,B,C) AVG = (A + B + C) / 3 PRINT " Average of three numbers : ";AVG END SUB Book Page 182 A. Write a program with a sub module to input radius in the main module and then print the area of a circle where A=PI*R^2(declare PI as global variable) Answer: DECLARE SUB AREA(R) INPUT "Enter radius : ", R DIM SHARED PI PI = 3.14 CALL AREA(R) END SUB AREA(R) A = PI * R ^ 2 PRINT " Area of circle : ";A END SUB B. Write a program with a sub-procedure to print the following series: 1, 1, 2, 3, 5 up to 10th terms. Answer: DECLARE SUB FIBO() CALL FIBO END SUB FIBO A = 1 B = 1 FOR I = 1 TO 10 PRINT A C = A + B A = B B = C NEXT I END SUB Book Page 185 A. Write a program to input multi-digit number and then find the sum of the odd digits of the number using sub-procedure. Answer: DECLARE SUB SUM(N) INPUT "Enter a number";N CALL SUM(N) END SUB SUM(N) S = 0 WHILE N<>0 R = N MOD 10 IF R MOD 2=1 THEN S = S + R END IF N = INT(N / 10) WEND PRINT"Sum of odd digits ";S END SUB B. Write a program to input multi-digit number and then find the sum of the even digits of the number using sub procedure. Answer: DECLARE SUB SUM(N) INPUT "Enter a number";N CALL SUM(N) END SUB SUM(N) S = 0 WHILE N<>0 R = N MOD 10 IF R MOD 2=0 THEN S = S + R END IF N = INT(N / 10) WEND PRINT"Sum of even digits ";S END SUB Book Page 186 A. Write a program to input your name and then print it in reverse form using the sub-procedure. Answer: DECLARE SUB REV(W$) INPUT "Enter name ";w$ CALL REV(W$) END SUB REV(W$) FOR I = LEN(W$) TO 1 STEP-1 C$ = C$+MID$(W$, I, 1) NEXT I PRINT"Reverse is ";C$ END SUB B. Write a program to input a string then print whether string is palindrome or not. Answer: DECLARE SUB PALIN(W$) INPUT "Enter name ";w$ CALL PALIN(W$) END SUB PALIN(W$) FOR I = LEN(W$) TO 1 STEP-1 C$ = C$ + MID$(W$, I, 1) NEXT I IF W$=C$ THEN PRINT"Palindrome " ELSE PRINT "Not Palindrome" END IF END SUB