谭浩强c++第三版5-3
作者:互联网
#include<iostream>
using namespace std;
//求一个3*3矩阵对角线元素之和
int main()
{
int a[3][3],sum=0;
cout << "请输入这个矩阵:" << endl;
for (int i = 0; i < 3; i++)
for (int j = 0 ; j < 3; j++)
cin >> a[i][j];
for (int i = 0; i < 3; i++)
for (int j =0 ; j < 3; j++)
if (i == j || i + j == 2)
sum += a[i][j];
cout << "对角线元素之和为:" << sum << endl;
return 0;
}
标签:std,cout,int,sum,第三版,c++,++,谭浩强,main 来源: https://blog.csdn.net/weixin_44817229/article/details/104818096