C语言实现3*3数组对角线之和示例

时间:2022-09-19 13:10:52

我就废话不多说了,直接上代码吧!

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#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数组对角线之和示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/DuckyLoser/article/details/79595210