C语言学习记录之------求一个3*3整型矩阵对角线元素的和
int main() {int arr[3][3], total = 0;// 输入矩阵元素for (int i = 0;i < 3;i++) {for (int j = 0;j < 3;j++) {scanf("%d", &arr[i][j]);}printf("\n");}// 计算求和for (int i = 0;i < 3;i++) {total += arr[i][i];}printf("total = %d\n", total);return 0;
}
输出结果: