Qbasic is one of the most popularly used high level programming language.
It is the best programming language for beginners.
I’m going to teach you some of the programs of qbasic.
Some of the terms used in Qbasic are:-
1) CLS:- CLS stands for Clear The Screen. This helps to erase all the output in the screen.
2) INPUT:- Input provides the interface where the user can input the data from keyboard.
3) PRINT:- PRINT helps to display the results in the screen.
4) Loop:- Loop means the repetition of the statement.
5) Variable: - Variable is a letter or a phrase which stores the assigned data and whose variable is changeable during program execution.
6) END:- END helps to end the program
Some of the simplest programs that helps you to learn the ABC of Qbasic are as follow::
A program to print the name, address and telephone of the people.
#1 A program to print the natural numbers from 1 to 50.
CLS
FOR Z = 1 TO 50
PRINT Z;
NEXT Z
END
OUTPUT
Description:
1) CLS which is located at the top of the program helps to clear the screen.
2) In the statement “FOR Z = 1 TO 50” , Z is the variable assigned ,1 is the starting value and 50 is the final value.
3) “PRINT Z;” helps to displays the value of variable “Z” and semicolon" ;" hels to print the value in horizontal way.
4) “NEXT Z” checks the value of Z. If the value of Z is less than the final value (i.e. 50) then once again the program is repeated from step 2 and the value of Z increment by 1 in every loop (repetition). If the value of Z meets the final value then the program steps out to the next statement.
5) END helps to terminate the program.
#2 A program to write your name 20 times.
CLS
INPUT “ENTER YOUR NAME”;N$
FOR I = 1 TO 20
PRINT N$
NEXT I
END
OUTPUT
Description
1. CLS which is located at the top of the program helps to clear the screen.
2. INPUT statement provides the interface where the user can provide the any value or data from keyboard.
3. N$ is the variable which holds the string(alphanumeric) type of data. When the user provides the data from the keyboard then that data is stored in the variable N$. (Note:- To store numeric value variable without $ sign is used.)
4. FOR I = 1 to 20 refers to the loop statement. The initial value is 1 and the final value is 20. It means that the looping occurs 20 times.
5. PRINT N$ helps to display the value of N$.
6. NEXT I checks the value of I. If the value of I is less than the final value (i.e. 20) then once again the program is repeated from step 3 (of the program) and the value of I increment by 1 in every loop (repetition). If the value of I meets the final value then the program steps out to the next statement.
7. END helps to terminate the program.
#3 A program to print the name, address and telephone of the people.
CLS
INPUT “ENTER YOUR NAME”;N$
INPUT “ENTER YOUR ADDRESS”;A$
INPUT “ENTER YOUR TELEPHONE NUMBER”;T
PRINT “Name”, ”Address” , ”Telephone”
PRINT N$ , A$ , T
END
Description
1. INPUT helps to get the value from the user.
2. N$ , A$ , T are the three variables used in the programs. N$ and A$ stores the string data whereas the T stores the numeric data.
3. PRINT “Name”, ”Address” , ”Telephone” helps to display the text inside inverted commas (“ “).
4. PRINT N$ , A$ , T helps to print the data stored in the variables
#4 A program to check whether the entered number is odd or even.
CLS
INPUT “ENTER A NUMBER”;N
R= N MOD 2
IF R = 0 THEN
PRINT “Even”
ELSE
PRINT “Odd”
END IF
END
Output
Description: -
1. INPUT helps to get the value from the user. It stores the data in the variable N. The data stored in variable N is numeric data.
2. R is the next numeric variable which stores the data after the calculation. It the step 3, R stores the value of N MOD 2. N MOD 2 is the calculation , where the variable N is modulus divided by 2. (MOD means the modulus division where the remainder is get when the variable is divided. OR it can be understood by the value remained less than the subtractor when a variable is repeatedly subtracted by the number.)
3. IF statements check the condition is whether true or false. In the step 4, if the value of R is equal to 0 then the condition is true but if the value of R is not equal to 0 then the condition is false.
4. If the condition is true then program jumps to step 5 and print the text in commas (“Even”)
5. If the condition is false then the program jumps into step 7 and print then text in commas (“Odd”). ELSE statement makes the program jump into if the condition is false.
6. END IF helps to terminate the IF statement.