-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEven_and_Odd_Indixes.cpp
49 lines (43 loc) · 1015 Bytes
/
Even_and_Odd_Indixes.cpp
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
/*
PROBLEM:
Given an array of integers, print two integer values:
First, the sum of all numbers which are even as well as whose index are even.
Second, the sum of all numbers which are odd as well as whose index are odd.
Print the two integers space separated. (Arrays is 0-indexed)
Input:
Given an integer denoting the size of array.
Next line will have a line containing ‘n’ space separated integers.
Constraints:
1<=n<=10^5
1 <= Ai <= 10^6
Output:
Two space separated integers denoting even and odd sums respectively.
Sample Input:
5
2 3 5 1 4
Sample Output:
6 4
CODE:
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=0,even=0,odd=0;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
if((arr[i]%2==0) && i%2==0)
{
even+=arr[i];
}
else if((arr[i]%2!=0) && i%2!=0)
{
odd+=arr[i];
}
}
cout<<even<<" "<<odd;
return 0;
}
//https://github.com/Aman9026/Codezen