Problem Description
输入一个正整数n(1<=n<=10),再输入n*n的矩阵,要求求该矩阵的下三角元素之和。
Input
输入包括n+1行。
第一行为整数n;
接下来的n行为矩阵数据。
Output
矩阵的下三角元素之和。
Sample Input
5
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
Sample Output
75
Hint
Source
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a[10][10],num=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
num+=a[i][j];
}
}
printf("%d",num);
return 0;
}
/***************************************************
User name: 小柳学渣
Result: Accepted
Take time: 0ms
Take Memory: 188KB
Submit time: 2019-01-27 20:34:01
****************************************************/