1a. Write
a program to accept a positive integer and then prints out all the positive
divisors of that integer in a column and in decreasing order. The program
should allow the user to repeat this process as many times as the user likes.
ANSWER:
DO
DO
INPUT “ENTER A POSITIVE INTEGER”, POST
LOOP
WHILE (POST < 1)
FOR
J = POST TO 1 STEP – 1
IF
(POST MOD J) = 0 THEN
PRINT
J
ENDIF
NEXT
J
INPUT
“DO YOU WANT TO COMPUTE ANOTHER (Y/N)”; RE$
LOOP
WHILE (RE$ = “y” OR RE$ = “Y”)
END
b. Write
a program to generate odd numbers divisible by 5, its square and product of
squares below 90 between 1 and 101
ANSWER:
LET PRD = 1
PRINT
”ODD NUMBER, SQUARE, PRODUCT OF SQUARE”
FOR
J = 5 TO 101 STEP 5
IF
(J MOD 2) <> 0 THEN
PRINT
J, J^2
PRD
= PRD * J^2
IF
PRD < 90 THEN
PRINT
PRD
ENDIF
ENDIF
PRINT
NEXT
J
END
2a A
positive integer n is said to be prime (or, “a prime”) if and only if n is
greater than 1 and is divisible only by 1 and n. for example, the integers 17
and 29 are prime, but 1 and 38 are not prime. Write a function that takes a
positive integer argument and returns as its value the integer 1 if the
argument is prime and return the integer 0 otherwise.
ANSWER:
DO
INPUT
“A POSITIVE INTEGER NUMBER”; N
LOOP
WHILE (N<0)
IF
N > 1 THEN
PRINT
“POSITIVE INTEGER STATUS = ”; SUM(N)
ELSE
PRINT
“1 IS NOT A PRIME NUMBER”
ENDIF
FUNCTION
SUM (N)
LET
M = 0
LET
J = INT (N^0.5)
FOR
I = 1 TO J
IF
(N MOD I = 0) THEN
M = M + 1
ENDIF
IF
M > 0 THEN
EXIT
FOR
ENDIF
NEXT
I
IF
M >= 1 THEN
SUM
= 0
ELSE
SUM
= 1
ENDIF
END
FUNCTION
B. Write
a program to add all the natural numbers below one thousand that are multiples
of 3 or 5
ANSWER:
LET
SUM = 0
FOR
J = 1 TO 999
IF
(J MOD 3 = 0) OR (J MOD 5 = 0) THEN
SUM
= SUM + J
ENDIF
NEXT
J
PRINT
“SUM OF NATURAL NUMBERS THAT ARE MULTIPLES OF 3 OR 5”; SUM
END
3 The table below captures a weekly sales data for a small retail shop
Product/day 1 2 3 4 5 6
Milk 20 45 20 40 50 35
Sugar 30 10 90 45 15 60
Notebook 10 20 80 12 15 50
File 34 24 50 16 25 50
Pencil 56 43 12 15 20 35
Biro 23 59 20 10 40 30
Develop
a program to determine the following:
(i)
Total
sales for the week
(ii)
The product
with highest total sales in the week
(iii)
The total
amount of sales for two products (e.g biro and pencil)
ANSWER:
DIM
PROD$(6), EPROD(6)
INPUT
SECTION
LET
SUM = 0
FOR
PROD = 1 TO 6
LET TOTAL = 0
INPUT “ENTER PRODUCT = ”; PROD$(PROD)
READ PROD$(PROD)
DATA “MILK”, “SUGAR”, ”NOTEBOOK”, “FILE”, “PENCIL”,
“BIRO”
FOR
D = 1 TO 6
INPUT “ENTER PRODUCT SALES”; AMT
READ
AMT
LET
TOTAL = TOTAL + AMT
NEXT
D
EPROD(PROD)
= TOTAL ‘COMPUTE TOTAL SLAES FOR EACH PRODUCT IN THHE WEEK’
SUM
= SUM + EPROD(PROD) “TOTAL SALES FOR THE
WEEK”
NEXT
PROD
DATA 20, 45, 20, 40, 50, 35
DATA
30, 10, 90, 45, 15, 60
DATA
10, 20, 80, 12, 15, 50
DATA
34, 24, 50, 16, 25, 50
DATA
56, 43, 12, 15, 20, 35
DATA
23, 59, 20, 10, 40, 30
‘COMPUTE
PRODUCT WITH HIGHEST TOTAL SALES’
LET
HSUM = 0
LET
PSUM = 0
FOR
D = 1 TO 6
IF (HSUM < EPROD(D)) THEN
HSUM = EPROD(D)
PSUM = D
ENDIF
NEXT
D
PRINT
“TOTAL SALES FOR THAT WEEK = ”; SUM
‘COMPUTE
TOTAL AMOUNT OF SLAES FOR TWO PRODUCTS’
FOR
J = 1 TO 5
FOR H = J + 1 TO 6
PRINT “SALES OF”; PROD$(J); “AND”;
PROD$(H); “=”; EPROD(J) + EPROD(H)
NEXT H
NEXT
J
END
This is really great...
ReplyDeleteyou welcome
ReplyDeletepls dis's what year past qst?
ReplyDelete