当前位置:网站首页>Matrix operation

Matrix operation

2022-06-22 08:10:00 Study hard 867

Given a n×n Matrix of , This problem requires the calculation of the matrix divided by the sub diagonal 、 The sum of all elements except the last column and the last row . The sub diagonal is the line from the upper right corner of the matrix to the lower left corner .

Input format :

Enter the first line to give a positive integer n(1<n≤10); And then n That's ok , Each line gives n It's an integer , Separated by spaces .

Output format :

Give the matrix in one row divided by the sub diagonal 、 The sum of all elements except the last column and the last row .

sample input :

4
2 3 4 1
5 6 1 1
7 1 8 1
1 1 1 1

sample output :

35

Code : 

#include <stdio.h>
int main(){
    int m=0,n=0,i=0,j=0;
    scanf("%d",&n);
    int a[n][n];
    for(i=0;i<n;i++)

  {
              for(j=0;j<n;j++)

            {
                   scanf("%d",&a[i][j]);
                   if(i!=n-1&&j!=n-1&&j!=n-1-i) 

                         { 
                               m=m+a[i][j];

                           }
            }
    
    }
    printf("%d",m);
    return 0;
} 

原网站

版权声明
本文为[Study hard 867]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220802076612.html