forked from sekayasin/MIU-Practice-Tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuestion15.txt
15 lines (14 loc) · 1.08 KB
/
Question15.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Question 15
Write a function that will return 1 if an integer array satisfies the following conditions and returns 0 otherwise.
1. it has even numbers of elements
2. Sum of all the numbers in the first half of the array is equal to the sum of all the numbers in the second half of the array.
If you are programming in Java, the function Signature is
int answerThree(int[] a)
Examples
-------------------|--------|-----------------------------------------------------------------------
| a | return | Explanation |
|-------------------|--------|-----------------------------------------------------------------------|
| {5,4,3,2,3,4,6,1} | 1 | *There are 8 (even) number of elements in the array. Thus condition 1 |
| | | satisfied. |
| | | *The sum of all the numbers in the first half = 5+4+3+2 = 14 |
-------------------|--------|-----------------------------------------------------------------------