我就废话不多说了,直接上代码吧! #define _CRT_SECURE_NO_WARNINGS 1#includestdio.h#includewindows.h int SUM(char arr[][3]){int i = 0;int j = 0;int sum = 0;for (i = 0; i 3; i++){for (j = 0; j 3; j++){if (i == j){sum += arr[i][
我就废话不多说了,直接上代码吧!
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<windows.h> int SUM(char arr[][3]) { int i = 0; int j = 0; int sum = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { if (i == j) { sum += arr[i][j]; } if (i + j == 2) { sum += arr[i][j]; } } } sum -= arr[1][1]; return sum; } int main() { char arr[3][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; printf("the answer is %d\n",SUM(arr)); system("pause"); return 0; }
以上这篇C语言实现3*3数组对角线之和示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持自由互联。