Lab 06
Lab 06
Lab 6 Arrays
Please test the correctness of your programs in Q-2 and Q-3 on PASS.
Q-1.
Write a program that defines and initializes an array of 10 integers.
int num[10] = {5, 10, 2, 5, 8, 8, 7, 9, 1, 5};
a) Write a for-loop to print out the contents of the array, one element in one line.
b) Modify the programs in question a), such that it prints a bar chart for the values in
the array as follows.
*****
**********
**
*****
********
********
*******
*********
*
*****
Q-2.
Write a program to read students’ mid-term test score (a whole number ranging
from 0 to 50), calculate the average score and prints the corresponding bar chart
for the grades as in Q-1-b.
Expected Outputs:
Example-1
Number of students?
3
Student 1:
30
Student 2:
20
Student 3:
50
Average = 33.33
******************************
********************
**************************************************
1/2
CS2311 Computer Programming 2024-25A
Q-3.
Write a program that reads two sets of integer elements (10 elements for each
set) and finds the intersection of two sets.
Hint-1. The elements of set A and B should be unique according to set properties.
Hint-2. The intersected element is the common element in both sets.
Expected Outputs:
Example-1
Enter 10 Elements of Set A:
1 2 3 4 5 6 7 8 9 10
Enter 10 Elements of Set B:
11 12 13 14 15 16 17 18 19 20
The Intersected Element of Set A and B are not Found.
Example-2
Enter 10 Elements of Set A:
1 2 3 4 5 6 7 8 9 10
Enter 10 Elements of Set B:
1 2 3 4 5 6 7 8 9 10
The Intersected Elements of Set A and B are:
1 2 3 4 5 6 7 8 9 10
Example-3
Enter 10 Elements of Set A:
1 2 3 4 5 6 7 8 9 10
Enter Elements of Set B:
1 3 5 7 9 11 13 15 17 19
The Intersected Elements of Set A and B are:
1 3 5 7 9
Example-4
Enter 10 Elements of Set A:
-1 -2 -3 -4 -5 -6 -7 -8 -9 -10
Enter Elements of Set B:
-1 -3 -5 -7 -9 -11 -13 -15 -17 -19
The Intersected Elements of Set A and B are:
-1 -3 -5 -7 -9
2/2