Tuesday, September 26, 2017

Debug the Qbasic Programs [SEE Qbasic Practice PART I]

1.      DECLARE SUB SUM (A, B, C)
PRINT A, B, C
PRINT SUM (A, B, C)
END

SUB SUM (A, B, C)
D=A+B+C
PRINT A
END

2.      DECLARE FUNCTION SUB (a, b, c)
CLS
INPUT a
INPUT b
INPUT c
PRINT “Average=SUB (a, b, c)
END

FUNCATION SUB (a, b, c)
S=a+b+c
AVEG= (a+b+c)/3
PRINT Aveg
SUB END

3.      DECLARE SUB correct( )
CLS
REM to calculate the area of rectangle
CALL SUB
END

SUB Correct
INPUT “enter length”;L
INPUT “enter breadth”;B
A= LENGTH* BREADTH
PRINT “area of rectangle=”;Area
SUB END

4.      Rem program to find the cube of the cube of a given number
DECLARE FUNCTION CUBE(R)
ENTER R
DISPLAY CUBE(R)
END

FUNCTION CUBE(R)
S=P^3
PRINT S
COMPLETE

5.      DECLARE FUNCTION Namaste(X,Y)
CLS
INPUT “Enter first number”; X
IMPUT ”Enter second number”; Y
Z=Namaste(X,Y)
PRINT “The sum of the given two numbers=”; W
END

FUNCTION Namaste(X,Y)
SUM=X+Y
RETURN SUM
END FUNCTION


6.      DECLARE FUNCTION SUM(a,b)
REM Program to sum given two numbers
Input ”Enter first number”; x
Input “Enter second number”; y
PRINT SUM(a,b)
END

FUNCTION SUM(x,y)
SUM=a+b
END

7.      FUNCTION SUM (m,n)
Rem to print sum of two numbers
a= 6
b= 7
DISPLAY SUM (a, b)
END

FUNCTION SUM (m,n)
S = m +n
S = SUM
END SUM

8.      CREATE FUNCTION Square(A)
Rem to print square of a number
CLS
Get “a number”; A
CALL square(A)
END

FUNCTION square(A)
Ans=A^2
Square=Ans
END Square(A)

9.      REM TO FIND THE SQUARE ROOT OF GIVEN NUMBER
DECLARE SUB SQUARE(N)
INPUT R
CALL SQUARE(A)
END
SUB SQUARE(A)
SQ = SQROOT(N)
PRINT S
FINISH


10.   DECLARE FUNCTION AREA (X)
CLS
REM TO FIND THE AREA OF CIRCLE
INPUT “ENTER THE VALUE OF RADIUS”;R
CALL  AREA (R)
END

FUNCTION AREA (X)
 AR=    (22/7)* R^2
AR=AREA
FUNCTION END

11.   REM to display the cube of supplied number.
CLS
DECLARE    FUNCTION   CUB(N)
INPUT “Number”;C
PRINT “Cube value of inserted number”;CUB(C)
END                                                                                                                

FUNCTION CUB(A)
C = A3
C = CUB
END FUNCTION

12.   FUNCTION SUM (m,n)
Rem to print sum of two numbers
a= 6
b= 7
DISPLAY SUM (a, b)
END

FUNCTION SUM (m,n)
S = m +n
S = SUM
END SUM


13.   DECLARE SUB series ( )
CLS
EXECUTE Series
END

SUB Series
A=2
B=2
FOR ctr=1 to 5
DISPLAY A; B
A=A+B
Loop ctr
END    series ( )

14.   DECLARE SUB Series()
CLS
EXECUTE Series
END

SUB Series()
REM program to generate  3 3 4 9 15 upto 20th terms.
A=3
B=3
FOR ctr= 10 to 1
DISPLAY A;B;
A=A+B
B=A+B
NEXT ctr
END Series()

15.   DECLARE SUB Fibonic ()
REM *Fibonic series*
CALL SUB Fibonic
END

SUB Fibonic
A=1
B=1
FOR x=1 to 10
DISPLAY a;
a=a+b
b=a+b
END Fibonic

16.   DECLARE SUB Series(.)
CLS
EXECUTE Series
END

SUB Series
REM  to generate 2 2 4 6 10….. upto 10th term
P=2
Q=2
FOR           Ctr=1 TO 5
DISPLAY P,Q,
P=P+Q
Q=P+Q
WEND
END Series()

17.   DECLARE SUB Series()
CLS
EXECUTE Series
END

SUB Series()
REM program to generate 1 1 2 3 5…. Up to 20th terms
A=1
B=1
FOR ctr= 10 TO 1
DISPLAY A;B;
A=A+B
B=A+B
NEXT ctr
END Series()

18.   REM to display the fibonacci series (1, 1, 2, 3, 5 upto 10th terms)
DECLARE FUNCTION fabi(x,y)
CLS
A=1
B=1
CALL (x,y)
END

SUB fabi(a, b)
FOR I = 1 to 10
C = A + B
A = B
B = C
PRINT A
NEXT I
SUB END

19.   DECLARE SUB series( )
CALL series ( )
END

SUB series ( )
B = 1
WHILE B <10
PRINT B CUBE 2
B = B + 2
NEXT
END SUB
FINISH

20.   DECLARE SUB SERIES( )
CLS
CALL SERIES
END

SUB SERIES ( )
REM  *Program to find the sum of integers up to 10*
S = 0
C = 1
WHILE C >=10
S = S + C
C + 1 = C
DISPLAY S
END
END SUB

No comments:

Post a Comment