您的位置:首页 > 其它

求一个3X3矩阵两条对角线上元素之和

2014-05-14 11:25 393 查看
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<Windows.h>
#include<stdio.h>

void main()
{
int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
int total=0;
for (int i = 0; i < 3; i++)
{
if (i != 2 - i)
total += a[i][i] + a[i][2 - i];
else
total += a[i][i];
}
printf("%d", total);

system("pause");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐