Do the given questions in QBASIC program and write the source code.
1. Write a program to store two numbers 30 and 20 in two different variables and display the sum, difference and product of the numbers.
2. Write a program to calculate and display an area of 22m long and 15m wide the rectangle shaped ground. Write a program that accepts temperature in Fahrenheit and displays equivalent temperature in Celsius. [Hint: C =5/9 x (F − 3 2)].
3. Write a program that accepts principal amount, number of years and rate of interest.
4. This program displays simple interest. Write programs to convert weight into:
a. Kilogram into pound [Hint :1Kg=2.2 Pounds]
b. Pound into kilogram
Answers
Explanation:
What is a program in QBASIC to find the sum of even numbers between 10 and 50?
How can a CSE/non CSE student from a tier 2/3 engineering college apply for off-campus placements in the tech giants like Microsoft, Google, Facebook, Intel, Amazon, etc.? How can I improve my CV in the 4 years of my B.Tech?
Let us start with some good news. These companies are as hungry for skilled developers, as much as a driven student is seeking an
Hello there,
The following is quick and dirty, but it should do the trick :
10 REM ‘Program to find the sum of of even numbers between 10 and 50’
20 CLS
30 LET s = 10
40 FOR i = 10 TO 50 STEP 2
50 LET s = s + i
60 NEXT i
70 PRINT "The sum of the numbers is "; s
80 END
Now, this is an easy example, and should produce a string of even numbers of the simplest sort.
For sophistication, we can add this :
10 REM ‘Program to find the sum of of even numbers between 10 and 50’
15 REM ‘Using i MOD 2 form’
20 CLS
30 LET s = 10
40 FOR i = s TO 50
50 IF i MOD 2 =0 THEN LET s = s + i
60 NEXT i
70 PRINT "The sum of the numbers is "; s
80 END
Where the Modulus (MOD) of 2 for even numbers is used to return a more precise result. Also, we can modify value s to whatever we want.
We can get even more sophisticated by putting in INPUT statements to take in user inputs for variables s and i . And so on.
Explanation:
PROGRAM TO DISPLAY SUM, PRODUCT, DIFFERENCE AND PRODUCT OF TWO / THREE NUMBERS
December 19, 2014
1. Enter any two numbers and display its sum.
REM PROGRAM TO DISPLAY SUM OF TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = A + B
PRINT “SUM OF TWO NUMBERS”; S
END
USING SUB PROCEDURE
DECLARE SUB SUM (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL SUM(A, B)
END
SUB SUM (A, B)
S = A + B
PRINT “SUM OF TWO NUMBERS”; S
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUM (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = SUM(A, B)
PRINT “SUM OF TWO NUMBERS”; S
END
FUNCTION SUM (A, B)
SU = A + B
SUM = SU
END FUNCTION
2. Enter any two numbers and display its difference.
REM PROGRAM TO DISPLAY DIFFERENCE OF TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
D = A - B
PRINT “DIFFERENCE OF TWO NUMBERS”; D
END
USING SUB PROCEDURE
DECLARE SUB DIFF (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL DIFF(A, B)
END
SUB DIFF (A, B)
D = A - B
PRINT “DIFFERENCE OF TWO NUMBERS”; D
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION DIFF (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
DI = DIFF(A, B)
PRINT “DIFFERENCE OF TWO NUMBERS”; DI
END
FUNCTION DIFF (A, B)
D = A - B
DIFF = D
END FUNCTION
3. Enter any two numbers and display its product.
REM PROGRAM TO DISPLAY PRODUCT OF TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
P = A * B
PRINT “PRODUCT OF TWO NUMBERS”; P
END
USING SUB PROCEDURE
DECLARE SUB PROD (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL PROD(A, B)
END
SUB PROD (A, B)
P = A * B
PRINT “PRODUCT OF TWO NUMBERS”; P
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION PROD (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
PR = PROD(A, B)
PRINT “PRODUCT OF TWO NUMBERS”; PR
END
FUNCTION PROD (A, B)
P = A * B
PROD = P
END FUNCTION
4. Enter any two numbers and display its average.
REM PROGRAM TO DISPLAY AVERAGE OF TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
AV = (A + B) / 2
PRINT “AVERAGE OF TWO NUMBERS”; AV
END
USING SUB PROCEDURE
DECLARE SUB AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL AVERAGE(A, B)
END
SUB AVERAGE (A, B)
AV = (A + B) / 2
PRINT “AVERAGE OF TWO NUMBERS”; AV
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
AVGR = AVERAGE(A, B)
PRINT “AVERAGE OF TWO NUMBERS”; AVGR
END
FUNCTION AVERAGE (A, B)
AV = (A + B) / 2
AVERAGE = AV
END FUNCTION
5. Enter any two numbers and display its sum, difference, product and average.
REM PROGRAM TO DISPLAY SUM, DIFFERENCE, PRODUCT AND AVERAGE OF TWO NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = A + B
D = A – B
P = A * B
AV = (A + B) / 2
PRINT “SUM OF TWO NUMBERS”; S
PRINT “DIFFERENCE OF TWO NUMBERS”; D
PRINT “PRODUCT OF TWO NUMBERS”; P
PRINT “AVERAGE OF TWO NUMBERS”; AV
END
USING SUB PROCEDURE
DECLARE SUB SUM (A, B)
DECLARE SUB DIFF (A, B)
DECLARE SUB PROD (A, B)
DECLARE SUB AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
CALL SUM(A, B)
CALL DIFF(A, B)
CALL PROD(A, B)
CALL AVERAGE(A, B)
END
SUB SUM (A, B)
S = A + B
PRINT “SUM OF TWO NUMBERS”; S
END SUB
SUB DIFF (A, B)
D = A - B
PRINT “DIFFERENCE OF TWO NUMBERS”; D
END SUB
SUB PROD (A, B)
P = A * B
PRINT “PRODUCT OF TWO NUMBERS”; P
END SUB
SUB AVERAGE (A, B)
AV = (A + B) / 2
PRINT “AVERAGE OF TWO NUMBERS”; AV
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION SUM (A, B)
DECLARE FUNCTION DIFF (A, B)
DECLARE FUNCTION PROD (A, B)
DECLARE FUNCTION AVERAGE (A, B)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
S = SUM(A, B)
D = DIFF (A, B)
P = PROD(A, B)
AV = AVERAGE(A, B)
PRINT “SUM OF TWO NUMBERS”; S
PRINT “DIFFERENCE OF TWO NUMBERS”; D
PRINT “PRODUCT OF TWO NUMBERS”; P
PRINT “AVERAGE OF TWO NUMBERS”; AV
FUNCTION SUM (A, B)
SU = A + B
SUM = SU
END FUNCTION
FUNCTION DIFF (A, B)
D = A - B
DIFF = D
END FUNCTION
FUNCTION PROD (A, B)
P = A * B
PROD = P
END FUNCTION
FUNCTION AVERAGE (A, B)
AVGR = (A + B) / 2
AVERAGE = AVGR
END FUNCTION
6. Enter any three numbers and display its sum, product and average.
REM PROGRAM TO DISPLAY SUM, PRODUCT AND AVERAGE OF THREE NUMBERS
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
S = A + B + C
P = A * B * C
AV = (A + B + C) / 3
PRINT “SUM OF THREE NUMBERS”; S
PRINT “PRODUCT OF THREE NUMBERS”; P
PRINT “AVERAGE OF THREE NUMBERS”; AV
END
USING SUB PROCEDURE
DECLARE SUB SUM (A, B, C)
DECLARE SUB PROD (A, B, C)
DECLARE SUB AVERAGE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THREE NUMBERS”; C
CALL SUM(A, B, C)
CALL PROD(A, B, C)
CALL AVERAGE(A, B, C)
END