C程序打印矩阵的边界元素之和
给定一个矩阵,我们需要打印矩阵的边界元素并显示它们的总和。
示例
请参阅下面给出的矩阵-
给定矩阵
1 2 3 4 5 6 7 8 9
边界矩阵
1 2 3 4 6 7 8 9
边界元素的总和:1+2+3+4+6+7+8+9=40
查找边界矩阵之和的逻辑如下-
for(i = 0; i程序
以下是C程序以打印矩阵的边界元素的总和-
#include#include int main(){ int m, n, sum = 0; printf(“\nEnter the order of the matrix : “); scanf(“%d %d”,&m,&n); int i, j; int mat[m][n]; printf(“\nInput the matrix elements\n”); for(i = 0; i 输出结果 执行以上程序后,将产生以下结果-
Enter the order of the matrix : 3 3 Input the matrix elements : 1 2 3 4 5 6 7 8 9 Boundary Matrix : 1 2 3 4 6 7 8 9 Sum of boundary is 40