You must complete Graphics: Introduction to CorelDRAW to unlock this Lesson.

BASIC PROGRAMMING: ONE-DIMENSIONAL ARRAY

CONTENT

1. Write BASIC program to:

(a) State data in a vector of 10 integers with and without a FOR_NEXT statement etc

(b) Calculate the average of a one-dimensional array with 100 numeric value

(c) Calculate the area of 10 different rectangles with and without the WHILE_END statement

(d) Output the sum of the first 100 integers

(e) Output the value elements of a given array.

(a) Write a program to put 10 integers into the memory and print them on the screen.

DIM A(10)

FOR 1 = 1 TO 10

READ A (1) // OR INPUT A (1) in an interactive session, i.e. through keyboard

PRINT A(1) // The PRINT statement output data/value of A(I) on the screen

NEXT I

DATA 80, 60, -10, 11, 100, 8, 99, 67, 9, 14 //DATA statement not required if INPUT

END // Statement is used

 

(b) Calculate the average of a one-dimensional array with 100 numeric values.

REM using WHILE…END

DIM value(100)

Count = 1

Total = 0

WHILE count < 101

Total = total + value(count)

Count = count + 1

PRINT “total =”, total

PRINT Average=”, total/100

END

 

REM using FOR…NEXT

DIM value(100)

Count=1

total =0

FOR count=1 TO 100

Total = total + value(count)

Count=count + 1

NEXT count

PRINT “Total=”,total

PRINT “Average=”,total/100

END

 

Evaluation

Write a BASIC program to compute and display the sum of first 100 integers

(c) Calculate the area of 10 different rectangles

REM using WHILE…END

Count=1

WHILE count < 11

Input “base”, b

Input “height”, h

Area = (b*h)/2

PRINT “AREA=”, area

Count=count + 1

END

 

REM using FOR…NEXT

FOR J = 1 TO 10

Input “base”, b

Input “height”, h

Area = (b*h)/2

PRINT “AREA=”, area

NEXT J

END

 

(d) Output the sum of the first 100 integers

REM using WHILE..END

Count = 1

Sum = 0

WHILE count < 101

PRINT count * 2

END

 

REM using FOR…NEXT

Count = 1

Sum = 0

FOR I = 1 TO 100

PRINT count * 2

NEXT I

END

 

EVALUATION

  1. Output the values of the elements in array TEST (30)
  2. Write a BASIC program that would read and display the following scores: 20, 50, 45, 56, 80, 60, 10, 30, 100, 79, in a row.

Lesson tags: Computer Science Lesson Notes, Computer Science Objective Questions, SS3 Computer Science, SS3 Computer Science Evaluation Questions, SS3 Computer Science Evaluation Questions Second Term, SS3 Computer Science Objective Questions, SS3 Computer Science Objective Questions Second Term, SS3 Computer Science Second Term
Back to: COMPUTER SCIENCE/ICT – SS3 > Second Term
© [2022] Spidaworks Digital - All rights reserved.
error: Alert: Content is protected !!