forked from sekayasin/MIU-Practice-Tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuestion2-sumEvenOdd.txt
22 lines (22 loc) · 1.76 KB
/
Question2-sumEvenOdd.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Question 2
Write a function that takes an array of integers as an argument and returns a
value based on the sums of the even and odd numbers in the array. Let X = the sum of the odd
numbers in the array and let Y = the sum of the even numbers. The function should return X - Y
The signature of the function is:
int f(int[] a)
Examples:
-----------------------|-----------------------------------------------------------------------
| if input array is | return |
|-----------------------|-----------------------------------------------------------------------|
| {1} | 1 |
|-----------------------|-----------------------------------------------------------------------|
| {1,2} | -1 |
|-----------------------|-----------------------------------------------------------------------|
| {1,2,3} | 2 |
|-----------------------|-----------------------------------------------------------------------|
| {1,2,3,4} | -2 |
|-----------------------|-----------------------------------------------------------------------|
| {3,3,4,4} | -2 |
|-----------------------|-----------------------------------------------------------------------|
| {} | 0 |
-----------------------------------------------------------------------------------------------