Sunday, December 19, 2021

Largest Element in Diagonal Matrix in C++

 Machine Problem in C++

// Write a program to find the largest element of the main diagonal 

// for an integer matrix: A(4.4) 

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Program Listing

// Write a program to find the largest element of the main diagonal // for an integer matrix: A(4.4) #include <iostream> using Matrix = int[4][4]; [[nodiscard]] int max_elem(const Matrix& m) { int max = m[0][0]; for (int row = 1, col = 1; row < 4 && col < 4; ++row, ++col) if (m[row][col] > max) max = m[row][col]; return max; } int main() { Matrix matrix = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; std::cout << "Max elem: " << max_elem(matrix) << "\n"; }

No comments:

Post a Comment