当前位置:网站首页>Function: find the sum of the elements on the main and sub diagonal of the matrix with 5 rows and 5 columns. Note that the elements where the two diagonals intersect are added only once. For example,
Function: find the sum of the elements on the main and sub diagonal of the matrix with 5 rows and 5 columns. Note that the elements where the two diagonals intersect are added only once. For example,
2022-07-04 00:41:00 【CTGU-Yoghurt】
subject :
Code details :
#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);
}
边栏推荐
- 功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
- Test the influence of influent swacth on the electromagnetic coil of quartz meter
- [CSDN Q & A] experience and suggestions
- What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
- ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
- From functional testing to automated testing, how did I successfully transform my salary to 15K +?
- [dynamic programming] leetcode 53: maximum subarray sum
- 不得不会的Oracle数据库知识点(一)
- [C language] break and continue in switch statement
- Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
猜你喜欢
Beijing invites reporters and media
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
Analysis and solution of lazyinitializationexception
BBS forum recommendation
The super fully automated test learning materials sorted out after a long talk with a Tencent eight year old test all night! (full of dry goods
[NLP] text classification still stays at Bert? Duality is too strong than learning framework
Cloud dial test helps Weidong cloud education to comprehensively improve the global user experience
Employees' turnover intention is under the control of the company. After the dispute, the monitoring system developer quietly removed the relevant services
Joint examination of six provinces 2017
Regular expression of shell script value
随机推荐
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
Stock price forecast
STM32 GPIO CSDN creative punch in
For loop
A-Frame虚拟现实开发入门
Sorry, Tencent I also refused
[C language] break and continue in switch statement
Unity elementary case notes of angry birds Siki college 1-6
Weekly open source project recommendation plan
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
MySQL is installed as a Windows Service
12. Go implementation of integer to Roman numeral and leetcode
Regular expression of shell script value
Generic
Swagger2 quick start and use
The FISCO bcos console calls the contract and reports an error does not exist
What is the future of software testing industry? Listen to the test veterans' answers
Wechat official account and synchronization assistant
How to use AHAS to ensure the stability of Web services?
ITK learning notes (VII) the position of ITK rotation direction remains unchanged