C语言实验——矩阵下三角元素之和 (sdut oj)

    xiaoxiao2021-03-26  7

    C语言实验——矩阵下三角元素之和

    Time Limit: 1000MS  Memory Limit: 65536KB

    Problem Description

    输入一个正整数n(1<=n<=10),再输入n*n的矩阵,要求求该矩阵的下三角元素之和。

    Input

    输入包括n+1行。 第一行为整数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; }
    转载请注明原文地址: https://ju.6miu.com/read-650161.html

    最新回复(0)