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
Hint
Author
参考代码
#include<stdio.h>
int main()
{
int a[10][10],n;
int i,j;
int sum = 0;
scanf("%d",&n);
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
scanf("%d",a[i]+j);
}
}
for(i = 0; i < n; i++)
{
for(j = 0; j <= i; j++)
sum += a[i][j];
}
printf("%d\n",sum);
return 0;
}
本文介绍了一个C语言程序,用于计算一个n*n矩阵的下三角元素之和。程序首先读取矩阵的大小n,然后接收n*n个整数作为矩阵元素,并最终输出下三角元素的总和。
1万+

被折叠的 条评论
为什么被折叠?



