Thursday 8 December 2022

QBasic

Writing QBasic Program 

========================================================================


QBASIC Statements:

 Any command or the instructions in the QBASIC is called a statement. Statements are classified into executable and non-executable. Executable statement specify actions and non-executable statements specify characteristics, arrangements and initial values of data.

Some of the QBASIC statements are:

 

CLS

REM

INPUT

LET

PRINT

END

PRINT USING

LINE INPUT

LPRINT AND LPRINT USING

READ….DATA

RESTORE

LOCATE

SWAP

 =====================================================

1. CLS statement:

 

This statement is used to clear the output screen. Generally it is used at the starting of the program.It clears the previous output from the display screen and makes the screen blank.

 Syntax: CLS

--------------------------------------------------------------------------------------------- 

 

2. REM statement:

 

This statement is used to put comments in the program. REM or Remarks is non-executable statement where single quotation(‘) is used.

 Syntax: REM <remark>

--------------------------------------------------------------------------------------------- 

 

3. INPUT statement:

 

The INPUT statement is used to accept data from the keyboard at the program execution time. It receives input from the keyboard during the execution of the program.

 Syntax: INPUT [“Message”] ; Variable

---------------------------------------------------------------------------------------------

 

 4. LET statement:

 

It is an an assignment statement which is used to assign value to a variable. LET is an optional statement.

 Syntax: LET [variable] = [expression]

 ---------------------------------------------------------------------------------------------

 

5. PRINT statement:

 

It is used to display the output on the screen. Question mark (?) also can be used instead of PRINT command to display on the screen.

 Syntax: PRINT[expression][{; | ,}]

---------------------------------------------------------------------------------------------

 6. END statement:

 

END statement is used to terminate the execution of the program. It stops the further processing of the program.

 Syntax: END

---------------------------------------------------------------------------------------------

 

7. PRINT USING STATEMENT

 

Syntax: PRINT USING “formatting string”; expression

 !        Displays only the first character of string

\n\    Prints first n+2 characters from the string

&       Displays all the string

#        Digit position is spacified

&&    Prints leading & sign

^^^^  Prints the number in exponential format

.         Decimal point position specification

 ===================================

QBASIC Statements

 

Add 2  Number

--------------------------------------------------------------------------------------------

Cls

Input "Enter First Number"; x

Input "Enter Second Number"; y

Print "Sum of "; x; " and "; y; " is "; x + y

End

 

Write a program to find the area of a rectangle in Qbasic.

FORMULA: Area of a Rectangle is length x breadth. Here length is variable l and breadth is variable b. And is the variable to store the value of the result and print it as output.

---------------------------------------------------------------------------------------------

Cls

Input "Enter the length "; l

Input " Enter the breadth "; b

Let A = l * b

Print " The area of rectangle="; A

End

--------------------------------------------------------------------------------------------- 

 

Write a program to find the area of the triangle.

FORMULA:  Area of triangle is ½ x base x height.

Here variable b is the base and h is the height. T is the variable to store the result and print it.

---------------------------------------------------------------------------------------------

Cls

Input "Enter the base"; b

Input " Enter the height"; h

Let T = 1 / 2 * b * h

Print " The area of triangle="; T

End

---------------------------------------------------------------------------------------------

 

Write a Qbasic program to find the area of the circle.

FORMULA : Area of a circle is 22/7 x radius^2. Here we use variable R as Radius. And C is the variable where we store the result.

---------------------------------------------------------------------------------------------

Cls

Input " Enter the radius"; R

Let C = 22 / 7 * R ^ 2

Print " The area of circle ="; C

End

---------------------------------------------------------------------------------------------

 

Write a program to find out the Simple Interest.

FORMULA : Simple Interest = Principle x Rate x Time / 100

---------------------------------------------------------------------------------------------

Cls

Input " Enter the Principal"; P

Input " Enter the Rate"; R

Input " Enter the Time"; T

Let I = P * T * R / 100

Print " The simple Interest = "; I

End

---------------------------------------------------------------------------------------------

 

 

 

 


No comments:

Post a Comment