array prince lab
array prince lab
Submission instructions
* Submit one .c file for each part of the assignment. Each of your .c files should be named as:
<your roll number>_A<assignment number>_<problem number>.c
For instance, if your roll number is 24ME10025, and if you are presently doing Assignment 1
which has 3 parts, then you should submit 3 separate .c files named as:
24ME10025_A1_1.c 24ME10025_A1_2.c 24ME10025_A1_3.c
* Submissions must be through the course Moodle, before the end of Lab session. Late
submissions will be penalized /not be accepted.
1. [15 Marks] In this assignment, we will perform set opera:ons (on sets of integers) using
arrays. Write a program that stores two sets of integers A and B as two integer arrays, and
performs the three opera:ons (i) union of A and B, (ii) intersec:on of A and B, (iii) the set
difference A - B.
The elements of each set (integers) should be input from the user. Each set can have at most
30 elements. You should first ask the user how many elements are there in each set, and
then use a loop to enter those many elements. Note that if the user inputs the same
element (integer) mul:ple :mes for a set, the element should be included in the set only
once. The program should print out the two sets A and B as entered by the user, and the
results of the three set opera:ons
An example run of your program can be:
2. [20 Marks] A meteorological department records daily temperatures (in degrees Celsius)
for N days. The temperatures are whole numbers (integers), and N is a user input (assume
1 ≤ 𝑁 ≤ 200). The department wants to analyze the temperature trends over this period.
Write a C program that,
- First, takes the number of days N as input from the user.
- Then, takes N integer temperatures as input and stores them in an array T, where T[i]
contains the temperature recorded on day i+1.
AUer reading the input, your program should compute and display,
- [2 Marks] The average temperature over the N days (rounded to two decimal places).
- [3 Marks] The number of days where the temperature was below 10°C.
- [5 Marks] The most frequently occurring temperature (mode). If mul:ple values qualify,
print any one of them.
- [5 marks] The highest temperature recorded and all the days when this temperature
occurred.
- [5 Marks] A temperature distribu:on chart (histogram) showing the count of days in each
of the following ranges:
-- Below 0°C
-- 0 to 9°C
-- 10 to 19°C
-- 20 to 29°C
-- 30 to 39°C
-- 40°C and above
Note, you are not allowed to use any addi:onal array other than T. An example run of your
program can be:
3. [15 Marks] In machine learning and data science, cosine similarity is a measure used to
determine how similar two vectors are, regardless of their magnitude. Given two vectors of
size 5, write C a program that computes their cosine similarity. The cosine similarity between
two vectors A and B is defined as:
𝐴. 𝐵
cos(𝜃) =
1|𝐴|1 1|𝐵|1
Where, 𝐴. 𝐵 is the dot product of vectors A and B and 1|𝐴|1 and 1|𝐵|1 are the Euclidean
norms of A and B. In your case a vector will be implemented by a 1-D array of integers.
Input Format:
- Five space-separated integers represen:ng vector A as an array.
- Five space-separated integers represen:ng vector B as another array.
Output Format:
- The cosine similarity value (rounded to 4 decimal places).
You can assume that neither vector is a zero vector (to prevent division by zero). If you
implement it right, you will see that the value of cosine similarity will be in [-1, 1]. You may
use math library for this program. A few example runs of your program can be: