search
HomeComputer TutorialsComputer KnowledgeReturns the sum of the surrounding elements of the two-dimensional array as the function value

Returns the sum of the surrounding elements of the two-dimensional array as the function value

The sum of the surrounding elements of the two-dimensional array is returned as the function value

The first for loop is used to calculate the sum of the top row and the bottom row of the matrix, and the second for loop is used to calculate the sum of the elements in the leftmost column and the rightmost column except the two elements. Finally, the two summations are added together to obtain the sum of the surrounding elements.

〔Source program〕

#include

#include

#define M 4

#define N 5

int fun(int a[M][N])

{int sum=0,i;

for(i=0;i

sum =a[0][i] a[M-1][i];

for(i=1;i

sum =a[i][0] a[i][N-1];

return sum ;

}

main()

{ int aa[M][N]={{1,3,5,7,9},

{2,9,9,9,4},

{6,9,9,9,8},

{1,3,5,7,0}};

int i,j,y;

clrscr();

printf("The original data is :\\n");

for(i=0;i

{for(j=0;j

printf("\\n");

}

y=fun(aa);

printf("\\nThe sum: %d\\n",y);

printf("\\n");

}

Sum of edge elements of two-dimensional array

private function Anyl(A()() AS INTEGER,byval m as integer,byval n as integer) as long

tol=sum_side(A,m,n)

print tol

if m=n then

sd=Diag(A,m)

sid=InDiag(A,m)

print sd

print sid

else

print "m≠n"

end if

end function

private function Sum_side(A()() AS INTEGER,byval m_side as integer,byval n_side as integer) as long

dim sum as long

sum=0

n_side=n_side-1

for i=0 to n step 1

sum=sum A(0)(i)

next i

m=m-2

for i=1 to m step 1

sum=sum A(i)(0)

sum=sum A(i)(n)

next i

m=m 1

for i=0 to n step 1

sum=sum A(m)(i)

next i

sum_side=sum

end function

private function Diag(A()() AS INTEGER,byval m as integer) as long

dim Sum_Diag as long

m=m-1

Sum_Diag=0

FOR i=0 to m step 1

Sum_Diag=Sum_Diag A(i)(i)

next i

Diag=Sum_Diag

end function

private function InDiag(A()() AS INTEGER,byval m as integer) as long

dim Sum_InDiag as long

m=m-1

Sum_Diag=0

FOR i=0 to m step 1

Sum_InDiag=Sum_InDiag A(i)(m-i)

next i

InDiag=Sum_InDiag

end function

The above is the detailed content of Returns the sum of the surrounding elements of the two-dimensional array as the function value. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
Atomic Heart The Game Is Not Ready to Load This Save [Solved] - MiniToolAtomic Heart The Game Is Not Ready to Load This Save [Solved] - MiniToolApr 30, 2025 am 12:50 AM

Due to some reasons, you may encounter the “Atomic Heart the game is not ready to load this save” error. In this post, php.cn collects the possible reasons for the issue and offers you 5 troubleshooting methods.

Expert Windows X-Lite Optimum 11 24H2 Installation GuideExpert Windows X-Lite Optimum 11 24H2 Installation GuideApr 30, 2025 am 12:49 AM

If you need to enjoy Windows 11 24H2 on a lower configuration computer, you can download Windows X-Lite Optimum 11 24H2 Home or Pro. Here this post on php.cn Software aims to show you Windows X-Lite Optimum 11 24H2 download and install.

Unsupported PCs Accidentally Receive Windows 11 22H2 - MiniToolUnsupported PCs Accidentally Receive Windows 11 22H2 - MiniToolApr 30, 2025 am 12:48 AM

Microsoft accidentally releases Windows 11 22H2 to the Windows Insiders in the Release Preview Channel. Some users think Microsoft has changed the hardware and system requirements for Windows 11. However, it is just a bug in Windows 11. You can follo

How to Use the On-Screen Keyboard on Windows 11/10/8/7? - MiniToolHow to Use the On-Screen Keyboard on Windows 11/10/8/7? - MiniToolApr 30, 2025 am 12:47 AM

On-Screen Keyboard is a virtual keyboard that is available on Windows 11/10/8/7. If you don’t know how to open and use it on your Windows computer, you can read this post from php.cn Software to get some related information.

PrivadoVPN Free Download for Windows, Mac, Android, iOS - MiniToolPrivadoVPN Free Download for Windows, Mac, Android, iOS - MiniToolApr 30, 2025 am 12:46 AM

PrivadoVPN is a free VPN service for Windows, macOS, Android, iOS, Android TV, etc. With this free VPN, you can access any content online without location restriction and stay anonymously when browsing the internet. Check how to download and install

How to Unforget a Bluetooth Device on iPhone/Android/Laptop? - MiniToolHow to Unforget a Bluetooth Device on iPhone/Android/Laptop? - MiniToolApr 30, 2025 am 12:44 AM

Wireless Bluetooth brings people many conveniences in modern life. When you don’t want to keep the Bluetooth device connected, you can choose to forget it. But how to reconnect and unforget the Bluetooth when you want to re-establish the connection?

10 Best VPNs for Netflix to Watch Movies and TV Shows - MiniTool10 Best VPNs for Netflix to Watch Movies and TV Shows - MiniToolApr 30, 2025 am 12:43 AM

To watch various Netflix movies and TV shows, you may use a VPN service. This post introduces some best free Netflix VPNs for your reference. For more useful computer tutorials and tools, you may go to php.cn Software official website.

Discovery Plus Error 400 – What Is It and How to Fix It? - MiniToolDiscovery Plus Error 400 – What Is It and How to Fix It? - MiniToolApr 30, 2025 am 12:42 AM

Discovery Plus error 400 is a commonly seen issue when you watch your favorite TV shows and movies on Discovery Plus. This article on php.cn Website will introduce Discovery Plus 400 and some solutions for this issue.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor