当前位置:网站首页>功能:求5行5列矩阵的主、副对角线上元素之和。注意, 两条对角线相交的元素只加一次。例如:主函数中给出的矩阵的两条对角线的和为45。
功能:求5行5列矩阵的主、副对角线上元素之和。注意, 两条对角线相交的元素只加一次。例如:主函数中给出的矩阵的两条对角线的和为45。
2022-07-04 00:34:00 【CTGU-Yoghurt】
题目:

代码详解:
#include <stdio.h>
#define M 5
int fun(int a[M][M])
{
/**********Program**********/
int i, j, sum = 0;
for (i = 0; i < M; i++)
{
sum += a[i][i];
sum += a[i][M - i - 1];
}
if (M & 1) sum -= a[M / 2][M / 2];
return sum;
/********** End **********/
}
int main()
{
int a[M][M] = { {1,3,5,7,9},{2,4,6,8,10},{2,3,4,5,6},{4,5,6,7,8},{1,3,4,5,6} };
int y;
y = fun(a);
printf("s=%d\n", y);
}边栏推荐
- Suggestions for improving code quality
- 不得不会的Oracle数据库知识点(一)
- 12. Go implementation of integer to Roman numeral and leetcode
- 2022 Software Test Engineer skill list, please check
- Regular expressions and text processors for shell programming
- Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
- Wechat official account and synchronization assistant
- A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
- HR disgusted interview behavior
- Sorry, Tencent I also refused
猜你喜欢

How will the complete NFT platform work in 2022? How about its core functions and online time?

功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。

Investment demand and income forecast report of China's building ceramics industry, 2022-2028

Double efficiency. Six easy-to-use pychar plug-ins are recommended

Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution

Interview script of Software Test Engineer

Self study software testing. To what extent can you go out and find a job?

STM32 key light

Struct in linked list

It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
随机推荐
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
[error record] configure NDK header file path in Visual Studio
Self study software testing. To what extent can you go out and find a job?
[PHP basics] session basic knowledge, application case code and attack and defense
老姜的特点
Global and Chinese market of process beer equipment 2022-2028: Research Report on technology, participants, trends, market size and share
On the day when 28K joined Huawei testing post, I cried: everything I have done in these five months is worth it
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
Vscode regular match replace console log(.*)
What insurance products should be bought for the elderly?
A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
[leetcode] interview question 17.08 Circus tower
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
2020.2.14
Several ways to set up a blog locally [attach relevant software download links]
How to trade spot gold safely?
Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition
What are the application fields of digital twins in industry?
MySQL winter vacation self-study 2022 12 (2)
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections