You are on page 1of 14

Course: CPE 102A - Computer Programming Experiment No.

: 7
Name: Alexandra Kyla Torres Section: EE21S1
Date Performed: November 20, 2021
Date Submitted: November 22, 2021
Instructor: Engr. Julie Ann Susa

LABORATORY ACTIVITY NO. 7


ARRAY
(One-Dimensional Array)
1. Objective(s):

The activity aims to introduce an array stored data in memory in the same size and type using analytical tools such as
algorithm, flowchart and program to evaluate the output based on the requirement.

2. Intended Learning Outcomes (ILOs):


The students shall be able to:

1. Construct a program applying variable arrays


2. Construct a program dealing with array, initialization and application
3. Apply the knowledge in arrays in solving complex problems involving one-dimensional array.

3. Discussion:
In programming, an array is a series of objects which are of the same size and type. Each object in an array is called an
array element. Arrays can have more than one dimension. A one-dimensional array is called a vector; a two-
dimensional array is called a matrix. Each element has the same data type although they may have different values.
The entire array is stored contiguously in memory, that is, there are no gaps between elements.
The following displays the indexes and values in an array with 10 elements of type int

Note: An array of integers or an array of characters or an array of anything that has a defined data type.
Syntax:
// initialization
int i, sum = 0, numbers [10];

//Storing a new value


for (i = 0; i < 10; i++) {
cout<<”Integers”<<i+1<<numbers[i];
}
//compute for total integer
for (int i = 0; i < 10; i++) {
sum += numbers[i];
}

cout<<”Total the integer”<<sum<<endl<<;


cout << endl << "The end!"

4. Resources:

DevC++

5. Procedure and Output

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

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.
ALGORITHM

NARRATIVE PSEUDOCODE
Step 1: Start Program. Step 1: Start.
Step 2: Input 10 integers. Step 2: Declare array of size 10.
Step 3: Print the total number of even integers, highest even Step 3: loop while all elements are not zero
Step 4: initialize array with 10 integers
integer, lowest even integer, total number of odd integers,
endloop
highest odd integer, and lowest odd integer. Step 5: initialize highestEven to 0
initialize highestOdd to 0
Step 4: End program.
initialize lowestEven to INT_MAX
initialize lowestOdd to INT_MAX
initialize numOfEven to 0
initialize numOfOdd to 0
Step 6: loop while index size is less than 10
Step 7: if array[index] is Even
if array[index] > highestEven
highestEven = array[index]
Step 8: End

if array[index] < lowestEven


lowestEven = array[index]
endif
FLOWCHART
add 1 to numOfEven
endif

if array[index] is odd
START
if array[index] > highestOdd
highestOdd = array[index]
endif
int arr[10];
if array[index] < lowestOdd
int flag lowestOdd
= 0; = array[index]
endif
add 1 to numOfOdd
endif
endloop
For
print value of lowestEven
i < 10
print value of lowestOdd
print value of highestEven
print value of highestOdd
print value of numOfEven
print value of numOfOdd
For cin>>arr[i]
i < 10

1
1
1
1 1
1

if
int highestEven = 0;
arr[i]==0
int highestOdd = 0;
int numOfEven = 0 ;
int numOfOdd = 0;
flag++ int lowestEven= INT_MAX;
int lowestOdd = INT_MAX;

if
flag<9;

for
i < 10

if
arr[i]%2==0

if if
arr[i]>= arr[i]>=
highestOdd highestEven

2 2
2 2

lowestOdd lowestEven
= arr[i] = arr[i]

numOfOdd++ numOfEven++

cout<<lowestEven;
cout<<lowestOdd;
cout<<highestEven;
cout<<highestOdd;
cout<<numOfEven;
cout<<numOfOdd;

END

Record your screen display:


QUESTIONS

1. What conditional operation is requires producing counting the even numbers?


= If num % 2 == 0
2. What conditional operation is requires producing counting the odd numbers?
= If num % 2 != 0
3. What are the variables needed to produce the desired output?
=The variables needed are i, evenNumbersCount, highestEvenNumber, lowestEvenNumber, oddNumbersCount,
highestOddNumber, lowestOddNumber.
4. What did you observe in arranging the numbers in ascending order?
= Even if arrange them in ascending order, the output will always still the same.
5. What did you observe in arranging the numbers in descending order?
= Even if arrange them in descending order, the output will always still the same.

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 using and record your screen display result.

int count, sum=0;

for (count = 0; count <=9; count ++)

{ c[count] = b[count] + a[count];

cout << c[count] ; }

ALGORITHM

NARRATIVE PSEUDOCODE
Step 1: Start program. Step 1: Start.
Step 2: Initialize sum = 0 and count = 0 Step 2: Set a[10] = {-10, 20, 30, 40 ,– 50, -60, -70, 30, 90,
Step 3: Set A and B. 10}
Step 4: Check if count is less than or equal to 9 then repeat Step 3: Set b[10] = {15, 12, 13,14, – 50, -60, -20, 25, 35, 30}
steps 5 to 7, otherwise, go to step 8. Step 4: Set sum = 0.
Step 5: Calculate. Step 5: For loop from count = 0 to 9.
Step 6: Print output. • Set c[count] = b[count] + a[count]
Step 7: Increment count by 1. Step 6: Print c[count].
Step 8: Display final output. Step 7: End.
Step 9: End program.
FLOWCHART

START

sum = 0
count = 0

A [10] = {-10, 20, 30, 40, –


50, -60, -70, 30, 90, 10}
B [10] = {15, 12, 13,14, – 50,
-60, -20, 25, 35, 30}.

Is count <=9?

c[count] = b[count] + a[count]

Print c[count]

count = count + 1

END
Record your screen display:
QUESTIONS

1. Refer to exercise no. 2, what is the value count [5]?


=-120 -90 55 125 40
2. Refer to exercise no. 2, what is the value count [7]?
= 55 125 40
3. What Refer to exercise no. 2, what is the output of the program if count is change to minus 5?
= 30 90 10 8393013 0 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?
= 8392765 0 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”; }

Write your answer:


2. Refer to No. 1, what is the value of x if c [2], d [3], n = 5 and m = 5?

Write your answer:


3. Refer to No. 1, what is the value of x if c [8], d [8] n=9 and m= 5

Write your answer:

6. Conclusion:

An exhibit in C/C++ or any programming language is an assortment of comparative information things put away at
bordering memory areas, and components can be gotten to haphazardly utilizing the lists of a cluster. Clients can store
an assortment of crude information types, for example, int, float, twofold, scorch, and so forth, of a specific kind. To add
to it, a cluster in C/C++ can store determined information types like constructions, pointers, and so on. We can utilize
common factors (v1, v2, v3) when we have a few articles, yet it becomes hard to oversee them with standard factors
assuming we need to store many examples. An exhibit can address many cases in a single variable. Actually, like some
other points in this course, amateurs should rehearse more to utilize clusters in programming completely.

You might also like