Laboratory Activity 7
Laboratory Activity 7
Lapada
CPE 223
LABORATORY ACTIVITY NO.7
ARRAY
(One-Dimensional Array)
EXERCISE No.1
Martin wants to create a program that requires the user to input 10 integers then print the total
number of even integers, highest even integer, lowest even integer, total number of odd integers,
highest odd integer, and lowest odd integer. If, however, the user inputs zero (0), the program will
display “You have not yet entered 10 integers.”
Below is the sample output of the program Martin created.
Enter the integers:
Integer 1: 15
Integer 2: 9
Integer 3: 71
Integer 4: 35
Integer 5: 17
Integer 6: 13
Integer 7: 63
Integer 8: 33
Integer 9: 97
Integer 10: 13
Total number of even integers : 0
Highest even integer : none
Lowest even integer : none
Total number of odd integers : 10
Highest odd integer : 97
Lowest odd integer :
1. Write the corresponding algorithm
a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given problem.
3. Construct the program and record your screen display result
NARRATIVE
Step 1: Input 10 integers integer.
inputted integers.
integer.
integer.
- Display Results
END
FLOWCHART
DISPLAY RESULTS
QUESTIONS
1. What conditional operation is requires producing counting the even numbers? In my program
syntax, I used for loop in checking upon the entered even integers and the if statement for
checking true value of for loop.
2. What conditional operation is requires producing counting the odd numbers? In my program
syntax, I used for loop in checking upon the entered odd integers and the if statement for checking
true value of for loop.
3. What are the variables needed to produce the desired output? The variable need to produce the
desired output are the array of integers which will which will be used in order to identify odd and
even using for loop and if-else statements
4. What did you observe in arranging the numbers in ascending order? I have observed that
whenever we want to arrange the numbers in ascending order, we must iterate from arr[1] to arr[n] over
the array, then compare the current element to its predecessor. If the key element is smaller than its
predecessor, compare it to the elements before. Move the greater elements one position up to make space
for the swapped element.
5. What did you observe in arranging the numbers in descending order? I have observed that in
arranging numbers in descending order, we need to sort the Array opposite on what we are doing
in arranging numbers in ascending order.
EXERCISE No. 2
Sam wants to create a program that required 20 integers. Suppose the following numbers are
the value input as A[10] = {-10, 20, 30, 40 ,– 50, -60, -70, 30, 90, 10} and B[10] = {15, 12, 13,14, –
50, -60, -20, 25, 35, 30}.
1. Write the corresponding algorithm
a. Narrative
b. Pseudocode
2. Create the equivalent flowchart based on the algorithm of the given problem.
3. Construct the program and record your screen display result
count ++)
Narrative
- Sam need size 20 of integers
- First Sam needs to create a basket where the integers will be stored
- By declaring basket a and b
-Second Sam need to show the stored item in the basket
-By using a loop we can now output each item stored in the basket
Pseudocode
-Start
int size to 10
Array a[size] = {input value};
Array b[size]= {input value};
for count = 0; count<size: count ++
print a[count];
endfor
for count = 0; count<size: count ++
print b[count];
endfor
-Stop
FLOWCHART
DISPLAY RESULT
QUESTIONS
3. What Refer to exercise no. 2, what is the output of the program if count is change to
minus 5? 25 1843102131 32796 1095501703 65316 5 32 43 54 -100 -120 -90 55
125 40
4. What Refer to exercise no. 2, what is the output of the program if count is change to
minus 2? -1513526217 65325 5 32 43 54 -100 -120 -90 55 125 40
SUPPLEMENTAL ACTIVITIES
1. The value of variables are A, B, n and m. Assuming n =5 and m =5. What will be the
output of x if A[10] = {-1, -2, -3, -4 ,– 5, -6, -7, -8, -9, -10} and B[10] = {1, 2, 3,4, 5, 6, 7,
8, 9, 10}?
int c, x, n, m, d ;
for (c = 0; c <= n ; c++ {
for (d = 0; d <= m ;
d++ { x = A[c] * B[d];
cout << x << "\t”;}
cout << "\n”; }
6. Conclusion:
I there for conclude that is the simplest form of an Array in which the
elements are stored linearly and can be accessed individually by specifying
the index value of each element stored in the array. And doing exercises
improves my skills in assessing and it improves my logical thinking