Qbaic programming question and answers.

1.      Design an algorithm that receives a positive integer as input and finds the sum of the digits that make up the integer. E.g. if the integer is 512, the sum = 5 + 1 + 2 = 8.

Answer;
1.      start
2.      write Enter any positive integer
3.      Read integer
4.      Result = 0
5.      While integer > 0
r = integer  MOD 10
result = result + r
n = (n – r)/10
6.      Write result
        stop


2.       Write a QBASIC program to print the squares of even numbers from 0 to 28.

Answer


jubilantrich.com qb64







3.      A plastic chair rental store in Navrongo rents a plastic chair for GHS 0.5 a day. If a customer rents more than 50 chairs he/she will receive a 10 percent discount. If a customer rents more than 100 chairs he/she will receive a 20 percent discount. Write a QBASIC program that greets a customer and then ask him/her to enter his or her name and the number of chairs that he/she wants to rent. The computer will then calculate the bill and print out the customer’s bill


a)      Write the algorithm
b)      Draw the flowchart
c)      Writ the program
Answers
A
1.      Start
2.      Write  You are welcome customer
3.      Write Please enter your name
4.      Get name
5.      Write Please, How many chairs do you want to rent?
6.      Get number
7.      If number > 50 AND number < 100
8.      Bill = (10/100)*0.5*number
9.      Write your bill is =
10.  Write bill
11.  Elseif number > 100
12.  Bill=(20/100)*0.5*number
13.  Write bill
14.  Else
15.  Write your bill is = 0.5*number
16.  stop

B
 


 






      
c
.jubilantrich.com-qb64 code





17. Study the QBASIC program below carefully. Identify and correct the errors.

CLS
this program will determine the area and perimeter of a rectangle.
PRINT Please enter the length = l
PRINT Please enter the width = w
P = 2 (l w)
a = l + w
PRINT
INPUT The area of the rectangle is = ; a
PRINT
INPUT The perimeter of the rectangle is = ; P
END


          Answer with corrections of errors



jubilantrich.com-qb64-program-code-output