当前位置:网站首页>功能:求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);
}
边栏推荐
- [leetcode] interview question 17.08 Circus tower
- 挖财帮个人开的证券账户安全吗?是不是有套路
- Introduction to thread pool
- Pytorch learning notes 5: model creation
- Recommendation of knowledge base management system
- What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
- 不得不会的Oracle数据库知识点(二)
- 2022 Software Test Engineer skill list, please check
- Axure resources and prototype tool Axure RP 9 download
- system. Exit (0) and system exit(1)
猜你喜欢
Data mining vs Machine Learning: what is the difference between them? Which is more suitable for you to learn
[about text classification trick] things you don't know
Entropy and full connection layer
Several ways to set up a blog locally [attach relevant software download links]
Pytorch learning notes 5: model creation
[C language] break and continue in switch statement
[NLP] text classification still stays at Bert? Duality is too strong than learning framework
STM32 GPIO CSDN creative punch in
Joint examination of six provinces 2017
ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
随机推荐
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Qtcharts notes (V) scatter diagram qscatterseries
MySQL winter vacation self-study 2022 12 (2)
Understanding of Radix
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
A method to solve Bert long text matching
Global and Chinese market of melting furnaces 2022-2028: Research Report on technology, participants, trends, market size and share
Selenium library 4.5.0 keyword explanation (4)
What is the future of software testing industry? Listen to the test veterans' answers
Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
What is the GPM scheduler for go?
Zipper table in data warehouse (compressed storage)
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
Idea a method for starting multiple instances of a service
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
MySQL winter vacation self-study 2022 12 (1)
Pytorch learning notes 5: model creation
ITK learning notes (VII) the position of ITK rotation direction remains unchanged