一、N-S流程图;
二、运行结果;
三、源代码;
cs
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
int main()
{
//初始化变量值;
int i = 0;
int j = 0;
int sum = 0;
int a[3][3] = { 0 };
//获取数组a的值;
printf("请输入9个整数!!!!\n");
//循环;
for (i = 0; i < 3; i++)
{
//列;
for (j = 0; j < 3; j++)
{
//提示用户;
printf("a[%d][%d]=", i, j);
//获取用户输入的数据;
scanf("%d", &a[i][j]);
}
}
//换行;
printf("\n");
//提示用户;
printf("您输入的矩阵为:\n");
//打印数组;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
//打印;
printf("%5d", a[i][j]);
}
//换行;
printf("\n");
}
//换行;
printf("\n");
//运算;
for (i = 0; i < 3; i++)
{
//运算;
sum = a[i][i] + sum;
}
//输出结果;
printf("对角线之和为:%d", sum);
return 0;
}