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>
#include <string.h>
int main()
{
int n;
int i,j,sum=0;
int a[11][11];
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(j<=i)
sum+=a[i][j];
}
}
printf("%dn",sum);
return 0;
}
/***************************************************
Result: Accepted
Take time: 0ms
Take Memory: 152KB
****************************************************/
#include <stdio.h>
#include <string.h>
int main()
{
int n;
int i,j,sum=0;
int a[11][11];
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
if(j<=i)
sum+=a[i][j];
}
}
printf("%dn",sum);
return 0;
}
/***************************************************
Result: Accepted
Take time: 0ms
Take Memory: 152KB
****************************************************/最后
以上就是踏实石头最近收集整理的关于SDUT-1172-->C语言实验——矩阵下三角元素之和的全部内容,更多相关SDUT-1172-->C语言实验——矩阵下三角元素之和内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复