-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddorEven.cpp
More file actions
52 lines (44 loc) · 786 Bytes
/
OddorEven.cpp
File metadata and controls
52 lines (44 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<algorithm>
#include<vector>
#include <array>
#include<cmath>
#include <string>
using namespace std;
string odd_or_even(const vector<int> arr)
{
string resulttotal;
int result = 0;
for (int i = 0; i < arr.size(); i++)
{
result += arr[i];
}
if (result % 2 == 0)
{
resulttotal = "even";
}
else
{
resulttotal = "odd";
}
return resulttotal;
}
int main()
{
cout << odd_or_even({});
return 0;
}
/*Description:
Task:
Given a list of integers, determine whether the sum of its elements is odd or even.
Give your answer as a string matching "odd" or "even".
If the input array is empty consider it as: [0] (array with a zero).
Examples:
Input: [0]
Output: "even"
Input: [0, 1, 4]
Output: "odd"
Input: [0, -1, -5]
Output: "even"
Have fun!
*/