C语言实验——矩阵下三角元素之和
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
输入一个正整数n(1<=n<=10),再输入n*n的矩阵,要求求该矩阵的下三角元素之和。
Input
输入包括n+1行。
第一行为整数n;
接下来的n行为矩阵数据。
第一行为整数n;
接下来的n行为矩阵数据。
Output
矩阵的下三角元素之和。
Example 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
Example Output
75
#include<stdio.h>
int main()
{
int a[10][10], i, j, n, sum, *p;
sum = 0;
p = a[0];
scanf("%d\n",&n);
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
scanf("%d",&*(p + i*n + j));
}
}
for(i = 0; i < n; i++)
{
for(j = 0; j <= i; j++)
{
sum += *(p + i*n + j);
}
}
printf("%d\n",sum);
return 0;
}