Professional Documents
Culture Documents
Laboratory Exercise: Course Code Description Laboratory Exercise No. Title of Activity
Laboratory Exercise: Course Code Description Laboratory Exercise No. Title of Activity
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 1 of 7
LABORATORY EXERCISE
1. Write a program that will accept five (5) integers and display them to the users. You are limited to using
only two (2) variables (including the array).
FLOWCHART PSEUDOCODE
SET i = 0
True DISPLAY
i<5 “Numbers [“+ i + 1
+ “]:”
False
ACCEPT x[i]
END
VS CODE
#include <iostream>
return 0;
}
1
Course Code CS201
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 2 of 7
LABORATORY EXERCISE
2. Write a program that will display an equilateral triangle with a height depending on the user. The minimum height is
1, the maximum height is 10. Use an array to display the specific character on the specific row. The array will be: { 0 :=
“A”, 1:= “B”, 2 := “C”, 3 := “D”, 4 := “E”, 5 := “F”, 6 := “G”, 7 := “H”, 8 := “I”, 9 := “J” }. You are limited to four (4)
variables only (including the array).
PSEUDOCODE
DECLARE x[ ], n
SET x TO “ABCDEFGHIJ”
INPUT n
DECLARE i
FOR (i = 0; i < = i + 1)
DECLARE s
FOR (s = 0; s<n-i-1; s = s+1)
OUTPUT “ “
LOOP
DECLARE t
FOR (t = 0; t < (i*2)+1; t = t + 1)
OUTPUT x[i]
LOOP
CALL DoEndline[]
LOOP
END
FLOWCHART
START
DECLARE
x[ ], n
2
Course Code CS201
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 3 of 7
LABORATORY EXERCISE
x[ ] = “ABCDEFGHIJ”
ACCEPT
n
DECLARE
i
i=0
False True
DECLARE
i<n s
s=0
False True
DECLARE
s<n–i-1 DISPLAY “ “
t
t=0 s=s+1
False True
t <(i*2) + 1
i=i+1 t=t+1
END
VS CODE
#include <iostream>
int main () {
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 4 of 7
LABORATORY EXERCISE
cout << endl;
//_pause ();
system("PAUSE");
return 0;
3. Write a program that will ascendingly sort six (6) integers from the user. Use only four (4)
variables (including the array).
PSUEDOCODE
DECLARE n[6]
DECLARE i
FOR (i = 0; i < 6; i = i + 1)
INPUT n[i]
LOOP
FOR (i = 0; i < 6; i = i + 1)
DECLARE t
FOR (t = 0; t < 6; t = t + 1)
IF n[i] > n[t] THEN
DECLARE temp
SET temp TO n[i]
SET n[i] TO n[t]
SET n[t] TO temp
END
LOOP 4
LOOP
Course Code CS201
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 5 of 7
LABORATORY EXERCISE
FLOWCHART
START
DECLARE
n [6]
DECLARE
i
i=0
False True
i<6
ACCEPT
n [i]
i=0
2
5
Course Code CS201
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 6 of 7
LABORATORY EXERCISE
i=i+1
False True
i<6
1
DECLARE
t
t=i
False True
t<6
i=i+1
False True
n[i] > n[t]
2
DECLARE
t=t+1 temp
3
4 temp = n[i]
DISPLAY “The sorted
numbers are: “+n[0] +”,” +
n[1] +”,” +n[2] +”,” +n[3] +” “
+n[4] +” and “ +n[5] +”.” n[i] = n[t]
n[t] = temp
END
VSCODE 3
#include <iostream>
int main () {
int n[6];
Laboratory
Title of
Exercise 007 Arrays
Activity
No.
Page 7 of 7
LABORATORY EXERCISE
cout << "The sorted numbers are: " << n[0] << ", " << n[1] << ", " << n[2] << ", " <<
n[3] << ", " << n[4] << " and " << n[5] << ".";
cout << endl;
//_pause();
system("PAUSE");
return 0;
I therefore conclude that this activity that arrays in C++ is used to store a collection of data in a
more systematic way.