Open GW BASIC editor by double clicking on the file.
By default GW basic is in direct mode. Direct mode mean when
you write the command it will be executed at once.
Program 1: Write a command
for adding two numbers 10 and 20.
Answer: PRINT 10 + 20
Explanation: PRINT command is used to print the
result of any action. And to add the numbers we use addition operator ( + ).
Program 2: Write a command
for multiplying two numbers 40 and 5.
Answer: PRINT 40 * 5
Explanation: PRINT command is used to print the
result of any action. And to multiply the numbers we use multiplication
operator ( * ) which is known as asterisk.
NOTE: Similarly for subtraction we will use the
negative operator ( - ) and for division we will use division operator ( / ) which
is known as forward slash.
Program # 3: Write a
command to evaluate the following expression.
40 + 12 * 3 – 2
Answer: PRINT 40 + 2 * 3 -2
Program # 4: Subtract the
numbers 100 and 45 by using variables.
Answer:
x = 100
y = 45
PRINT x – y
Explanation: In this program we used two variables x
and y and initialize them with values 100 and 45 simultaneously. And then we
use the PRINT command to display our result.
What is variable?
A variable is a named memory location which is used to store
program’s input and its computational results during program execution.
Program # 5: Write a command
that display “HELLO PAKISTAN ”
on output screen.
Answer: PRINT “HELLO PAKISTAN ”
Explanation: In this program we are trying to display
a text string “HELLO PAKISTAN ”.
And whenever we work with strings we use double quotation marks.
What is concatenation?
Answer: Concatenation is the process of combining or joining
two or more text strings. And in GW Basic we use plus sign ( + ) to combine.
Program 6: Write a command
which concatenate two strings, “PAKISTAN ”
and “ZINDABAD”.
Answer: PRINT “PAKISTAN ” + “ZINDABAD”
Program 7: Write commands
to solve the following expressions. (i) 23 (ii) 37 (iii)
square of 10
Answer:
PRINT
2^3
PRINT
3^7
PRINT 10^2
Explanation: Carrot sign ( ^ ) is used for taking
power or exponent.
Program 7: Write a command
to calculate the modulus or remainder by dividing 13 with 2.
Answer: PRINT 13 MOD 2
Explanation: MOD command is used to take modulus or
remainder of a division.
No comments:
Post a Comment