[Arrays]D. Liang 6.18 Summing the major diagona in a matrix

Description

Write a function that sums all the integers in the major diagona in a matrix of integers.

The matrix is 4 * 4. Using the flowing function header:

int sumMajorDiagona(int matrix[4][4])

Hint

You should submit the implementation of the function but do not submit the main() function.

Problem Source: 程序设计I Chapter6 Arrays

Source.h

int sumMajorDiagona(int matrix[4][4]);
//   Date:2020/4/24
//   Author:xiezhg5
int sumMajorDiagona(int matrix[4][4])
{
    int i,sum=0;
    for(i=0;i<4;i++)
    sum=sum+matrix[i][i];  //计算主对角线元素和 
    return sum;
}
原创文章 268 获赞 307 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/105742396