File tree 2 files changed +47
-0
lines changed
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Don't track content of these folders
2
2
/.vscode /
3
3
# Compiled source #
4
+ * .out
Original file line number Diff line number Diff line change
1
+ /*
2
+ Given an array of integers, print two integer values:
3
+ First, the sum of all numbers which are even as well as whose index are even.
4
+ Second, the sum of all numbers which are odd as well as whose index are odd.
5
+ Print the two integers space separated. (Arrays is 0-indexed)
6
+ Input:
7
+ Given an integer denoting the size of array.
8
+ Next line will have a line containing ‘n’ space separated integers.
9
+ Constraints:
10
+ 1<=n<=10^5
11
+ 1 <= Ai <= 10^6
12
+ Output:
13
+ Two space separated integers denoting even and odd sums respectively.
14
+ Sample Input:
15
+ 5
16
+ 2 3 5 1 4
17
+ Sample Output:
18
+ 6 4
19
+ */
20
+ #include < bits/stdc++.h>
21
+ using namespace std ;
22
+ int main (){
23
+ int n;
24
+ cin >> n;
25
+ int arr[n];
26
+ for (int i = 0 ; i < n; i++)
27
+ {
28
+ cin >> arr[i];
29
+ }
30
+
31
+ long long int os = 0 , es = 0 ;
32
+
33
+ for (int i = 0 ; i < n; i++)
34
+ {
35
+ if (i % 2 == 0 and arr[i] % 2 == 0 )
36
+ {
37
+ es += arr[i];
38
+ }
39
+ else if (i % 2 != 0 and arr[i] % 2 != 0 )
40
+ {
41
+ os += arr[i];
42
+ }
43
+ }
44
+ cout << es << " " << os << " \n " ;
45
+ return 0 ;
46
+ }
You can’t perform that action at this time.
0 commit comments