2024_2

 avatar
user_1041599
c_cpp
a month ago
739 B
1
Indexable
2kolok_SP
#include <iostream>
#include <cctype>
#include <cstring>
#include <iomanip>
using namespace std;




int main() {
    int m,n;
    cin>>m>>n;
    int arr[m][n];
    //input array
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>arr[i][j];
        }
    }
    
    int k = 2;
    while(k<=m and k<=n)
    {
        int sum=0;
        for(int i = 0; i<k; i++)
        {
            for(int j=0;j<k;j++)
            {
                if(i==0 and j < k-1)
                    sum+=arr[i][j];
                if(i == k-1 and j > 0)
                    sum+=arr[i][j];
                if(i+j == k-1)
                    sum+=arr[i][j];
            }
        }
        cout<<sum<<endl;
        k++;
    }

}
Leave a Comment