0% found this document useful (0 votes)
11 views

Lab 2 - CEN 110

The document provides sample inputs and outputs for several programming problems involving arrays and functions. The problems include counting numbers over the average, summing two arrays, finding the difference between the maximum and minimum value, row-wise subtraction of minimum values, and z-score normalization.

Uploaded by

lina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lab 2 - CEN 110

The document provides sample inputs and outputs for several programming problems involving arrays and functions. The problems include counting numbers over the average, summing two arrays, finding the difference between the maximum and minimum value, row-wise subtraction of minimum values, and z-score normalization.

Uploaded by

lina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Laboratory 2

Note: ALL Exercises must be solved using Functions and Arrays.

Number of Numbers over Average

You are given a series of numbers, show the number of numbers which are greater than the average.

Input specification
The first number is the number of numbers (n) in the series where 1 < n ≤ 100.000. Then you will be given n
integer numbers where each of the is between -10.000 and 10.000.

Output specification
Just give one number which shows the number of numbers which are greater than the average of the series.

Sample Input I:
5
12345

Sample Output I:
2

Sample Input II:


5
-898 -833 570 245 629

Sample Output II:


3

(3 functions - read, average, aboveAvg)


http://acm.epoka.edu.al:8888/en/problem-pid-c49b

The sum of two arrays

You will be first given one number (n) which is followed by two series of integers (n space-separated values).
Calculate the sum of two series and show them.

Input specification
You will be given one integers (n) in the first line, and 1 ≤ n ≤ 10.000. The following two lines contain a
two series of integer numbers a[n] and b[n] where -1000 ≤ a[n], b[n] ≤ 1000.

Output specification
You will give one serie, which is the sum serie of two input series.

Sample Input II
Sample Input I
5 7
36954 5 8 4 -9 3 2
25627 -6 9 -5 8 2 5

Sample Output I Sample Output II


5 11 15 7 11 14 3 12 -7 8 2 -6

http://acm.epoka.edu.al:8888/en/problem-pid-c7fc (2 functions - read, sum)


The difference between max and min.

You will be first given one number (n) which is followed by one serie of integers (n space-separated values).
Calculate the difference between max and min in the array.

Input specification
You will be given one integers (n) in the first line, and 1 ≤ n ≤ 10.000. The following line contains a serie of
integer numbers a[n] where -10000 ≤ a[n] ≤ 10000.

Output specification
Show the difference between max and min element in the serie.

Sample Input I Sample Input II


5 6
36954 5 8 4 -9 3 2

Sample Output I Sample Output II


6 17

http://acm.epoka.edu.al:8888/en/problem-pid-c7fa (3 functions - read, max, min)

Row Min Subtraction

In a research, your professor has realized that the data he is


working on has some noise. For this reason, he wants to subtract
the smallest value of every row from the row elements. As a
result, the smallest number of every row will be 0.

Question: Write a program that is going to get n rows of m


numbers. Then, the program will subtract the smallest value of
every row from the row elements.
Note: Pay attention that there is memory limit in this question.

Input specification
In the beginning, you will be given 2 integers:

• the number of rows (n): an integer between 0 and 5000


• the number of numbers in every row (m): an integer between 0 and 1000

then in the following n lines you will be given m integers which are between -10000 and 10000.

Output specification
Show m integers in n lines.

Sample Input I Sample Output I


3 6 4 5 0 5 0 6
5 6 1 6 1 7 5 0 10 19 8 7
10 5 15 24 13 12 5 0 12 2 3 11
9 4 16 6 7 15

Explanation: The min of first row is 1, thus, 1 has been subtracted from the first row elements.
The min of the second row is 5. Similarly, 5 has been subtracted from the second row elements...
http://acm.epoka.edu.al:8888/en/problem-pid-c502 (3 functions - read, min, substraction)

ZScore normalization

There are several methods to put the items in the same scale. In Z-score normalization arithmetic mean is
subtracted from each data item and the result is divided by the standard deviation.

where μ is the arithmetic mean and σ is the standard deviation of the sequence.

Question: Write a program that reads a sequence of numbers and then normalizes them using ZScore.

Input specification
You will be first given a number (n) the number of numbers, where 0 ≤ n ≤ 5000. Then in the following line,
you will be given n integers which are between -50,000 and 50,000.

Output specification:
Show the normalized sequence with two digits precision.

Sample Input I Sample Output I


5 0.62 -0.42 1.14 -1.46 0.10
9 7 10 5 8

Explanation: There are 5 numbers given. And, arithmetic mean μ = 7.8 and σ = 1.9235. If μ is subtracted
from all the numbers and then divided by σ, we have the given sequence.

http://acm.epoka.edu.al:8888/en/problem-pid-c6b6?ps=15&smt=7&smpwid=0 (4 functions- read, sum,


stdDev, norm)

You might also like