Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 720 Bytes

14.md

File metadata and controls

33 lines (23 loc) · 720 Bytes
 vector<int> sumTriangles(const vector<vector<int> >& matrix, int n)
    {
        
        vector<int>v;
        int sum =0;
        
        for(int i=0;i<n;i++)     //upper
        {
            for(int j=i;j<n;j++)
                sum+=matrix[i][j];
        }
        
    // cout<<"sum="<<sum;
        
        v.push_back(sum);
        sum=0;
        
        for(int i=0;i<n;i++)        //lower
        {
            for(int j=0;j<=i;j++)
                sum+=matrix[i][j];
        }
        
        v.push_back(sum);
        
        return v;
        

    }