Infosec.Pub
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
amargo85 to C++@programming.devEnglish · 2 years ago

C++ Matrix Sum Challenge

chat-to.dev

external-link
message-square
0
link
fedilink
  • cross-posted to:
  • C++Discussion@chirp.social
-1
external-link

C++ Matrix Sum Challenge

chat-to.dev

amargo85 to C++@programming.devEnglish · 2 years ago
message-square
0
link
fedilink
  • cross-posted to:
  • C++Discussion@chirp.social
You are challenged to create a C++ program that performs the sum of two matrices. Your task is to implement a function or method that takes two matrices as input, adds them element by element and returns the resulting matrix. 1. Your program should ask the user to enter the number of rows and columns for each matrix. 2. The dimensions of the two matrices must be compatible for the sum, i.e. the number of rows and columns must be the same for both matrices. 3. Once the dimensions have been entered, the program asks the user to enter the elements of each matrix. 4. Once the elements have been entered, the program must calculate the sum of the two matrices. 5. Finally, the program should display the resulting matrix. **Example**: ```cpp Enter the number of rows and columns for the first matrix: 2 3 Enter the elements of the first matrix: 1 2 3 4 5 6 Enter the number of rows and columns for the second matrix: 2 3 Enter the elements of the second matrix: 7 8 9 10 11 12 The sum of the two matrices is 8 10 12 14 16 18 ``` **Notes**: * You can choose to implement the solution as a function or a complete program. * Make sure you handle cases where the dimensions of the matrices are not compatible for the sum. * Test your program with different sets of matrices to ensure that it is working correctly. To publish your answer all you have to do is register and use the tool [here](https://chat-to.dev/createpost). Just one more thing, don't forget to use markdown to style your code.
alert-triangle
You must log in or # to comment.

C++@programming.dev

cpp@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !cpp@programming.dev

The center for all discussion and news regarding C++.

Rules

  • Respect instance rules.
  • Don’t be a jerk.
  • Please keep all posts related to C++.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 4 users / day
  • 52 users / week
  • 175 users / month
  • 333 users / 6 months
  • 15 local subscribers
  • 2.17K subscribers
  • 346 Posts
  • 629 Comments
  • Modlog
  • mods:
  • farados@vlemmy.net
  • Nihili0@programming.dev
  • lysdexic@programming.dev
  • BE: 0.19.13
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org