当前位置:网站首页>功能:求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);
}边栏推荐
- Eight year test old bird, some suggestions for 1-3 year programmers
- Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
- [PHP basics] cookie basics, application case code and attack and defense
- Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
- 1214 print diamond
- 不得不会的Oracle数据库知识点(四)
- 网上的低佣金链接安全吗?招商证券怎么开户?
- How to trade spot gold safely?
- (Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
- Struct in linked list
猜你喜欢

Generic

Report on the construction and development mode and investment mode of sponge cities in China 2022-2028

Zipper table in data warehouse (compressed storage)

Interview script of Software Test Engineer

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

A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders

Analysis: misunderstanding of choosing WMS warehouse management system

Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing

Introducing Software Testing

Struct in linked list
随机推荐
For loop
【leetcode】300. Longest increasing subsequence (dynamic programming, dichotomy)
P1629 postman delivering letter
Zipper table in data warehouse (compressed storage)
Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
Entropy and full connection layer
[PHP basics] session basic knowledge, application case code and attack and defense
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
Global and Chinese markets for coronary artery disease treatment devices 2022-2028: Research Report on technology, participants, trends, market size and share
What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
Pytest unit test framework: simple and easy to use parameterization and multiple operation modes
[software testing] you haven't mastered these real interview questions of big companies?
A dichotomy of Valentine's Day
国元证券开户是真的安全可靠吗
Att & CK actual combat series - red team actual combat - V
Analysis: misunderstanding of choosing WMS warehouse management system
网上的低佣金链接安全吗?招商证券怎么开户?
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
8. Go implementation of string conversion integer (ATOI) and leetcode
Private project practice sharing populate joint query in mongoose makes the template unable to render - solve the error message: syntaxerror: unexpected token r in JSON at