Computer Programming II – Lab Activity 02
Problem 1: Find the Smallest Integer in the Array
The smallest integer in an array is the value with the lowest numerical value among all elements.
Rules:
1.
2.
3.
4.
5.
The user inputs the number of integers.
The user inputs the array of integers based on the given number.
Traverse all elements in the array.
Compare each value to find the smallest one.
Display the smallest integer found.
Examples:
Test Cases
Input
[5, 2, 9, 1, 7]
[10, 3, 6, 8]
[4]
[-4, -2, -9, -1]
Output
Smallest number is 1
Smallest number is 3
Smallest number is 4
Smallest number is -9
***Additionally, before the program terminates, ask the user if they would like to run the
program again.
Problem 2: Intersection of Two Lists
Implement a function that finds the intersection of two lists. The function should return
all elements that are present in both lists. Both lists are input by the user.
Rules:
1. The user inputs the number of elements for list a.
2. The user inputs the elements of list a.
3. The user inputs the number of elements for list b.
4. The user inputs the elements of list b.
5. Traverse list a.
6. Check which elements in list a are also found in list b.
7. Store the common elements in a new list.
8. Display the resulting intersection list.
Examples:
Test Cases
Input
a = [1, 2, 2, 3], b = [2]
a = [4, 5, 6], b = [7]
a = [1, 1, 1], b = [1]
a = [10, 20, 30], b = [20, 40]
Output
[2, 2]
[]
[1, 1, 1]
[20]
***Additionally, before the program terminates, ask the user if they would like to run the
program again.
Prepared by: Jaydee C. Ballaho
Computer Programming II – Lab Activity 02
Problem 1: Find the Mean of the Integers (Quiz Scores)
The mean of the integers is the average value obtained by adding all the numbers and dividing
by the total count. In this problem, the integers represent quiz scores, and the user must first
specify how many quizzes there are.
Rules:
1.
2.
3.
4.
5.
6.
The user inputs the number of quizzes.
The user inputs the quiz scores based on the given number.
Add all the quiz scores.
Count the total number of quizzes.
Divide the total sum by the number of quizzes.
Display the mean (average) score.
Examples:
Test Cases
Input
4 → [80, 85, 90, 75]
3 → [70, 70, 70]
1 → [100]
5 → [60, 75, 85, 90, 80]
Output
Mean score is 82.5
Mean score is 70
Mean score is 100
Mean score is 78
***Additionally, before the program terminates, ask the user if they would like to run the
program again.
Problem 2: Difference Between Two Lists
Implement a function that computes the difference between two lists. The function should remove
all occurrences of elements from the first list (a) that are present in the second list (b). Both lists
are input by the user.
Rules:
1. The user inputs the number of elements for list a.
2. The user inputs the elements of list a.
3. The user inputs the number of elements for list b.
4. The user inputs the elements of list b.
5. Traverse list a.
6. Remove all elements from list a that are also found in list b.
7. Display the resulting list.
Examples:
Test Cases
Input
a = [1, 2, 2, 3], b = [2]
a = [4, 5, 6], b = [7]
a = [1, 1, 1], b = [1]
a = [10, 20, 30], b = [20, 40]
Output
[1, 3]
[4, 5, 6]
[]
[10, 30]
***Additionally, before the program terminates, ask the user if they would like to run the
program again.
Prepared by: Jaydee C. Ballaho