You are given a two-dimensional 3*3 array starting from A [0][0]. You should add the alternate elements of the array and print its sum. It should print two different numbers the first being sum of A 0 0, A 0 2, A 1 1, A 2 0, A 2 2 and A 0 1, A 1 0, A 1 2, A 2 1.
Example:
Input: a00 = 1, a10 = 2, a20 = 3, a01 = 4, a11 = 5, a21 = 6, a02 = 7, a12 = 8, a22 = 9
Output:
25 20
Approach:
C++
#include <bits/stdc++.h>using namespace std;int main(){long long a00 = 1, a10 = 2, a20 = 3;long long a01 = 4, a11 = 5, a21 = 6, a02 = 7;long long a12 = 8, a22 = 9;long long ans1 = 0;long long ans2 = 0;ans1 = a00 + a02 + a11 + a20 + a22;ans2 = a01 + a10 + a12 + a21;cout << ans1 << "\n"<< ans2 << "\n";return 0;}
No comments:
Post a Comment