//m行,n列的矩阵,i表示行,j表示列
//s1为各行元素之和,s2为各列元素之和,k为行数,h为列数
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
for (i = 0; i < m; i++)
{
a[i][j] = a[i][0];
for (j = 0; j < n; j++)
{
s1 += a[i][j];
}
b[k] = s1;
k++;
s1 = 0;
}
for (i = 0; i < k; i++)
{
cout << b[i]<<" ";
}
for (j = 0; j< n; j++)
{
a[i][j] = a[0][j];
for (i = 0; i < m; i++)
{
s2 += a[i][j];
}
c[h] = s2;
h++;
s2 = 0;
}
for (i = 0; i < h; i++)
{
cout << c[i] << " ";
}
矩阵各行、各列求和
最新推荐文章于 2023-01-05 16:49:49 发布