first Enter your Matrixes Size(the sizes must be equal) second fill your matrixes third overload the (+) operators
matrix C= Matrix A + Matrix B
matrix C
=
| 9 | 4 |
| 32 | 12 |
matrix A
| 4 | 1 |
| 20 | 6 |
Matrix B
| 5 | 3 |
| 12 | 6 |
| 9 | 4 |
| 32 | 12 |
| 4 | 1 |
| 20 | 6 |
| 5 | 3 |
| 12 | 6 |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhay ShankerRank #375 · 6.7K reputationPosted Mar 3, 2014, 4:50 AM EST
Console.Write("Please enter No. of Rows :: ");introw =int.Parse(Console.ReadLine());Console.Write("Please enter No. of Columns :: ");intcolumn =int.Parse(Console.ReadLine());int[,] matrix1 =newint[row, column];int[,] matrix2 =newint[row, column];int[,] matrix3 =newint[row, column];Console.WriteLine("Please provide matrix data :: for "+ row +" X "+ column);for(intk=0; k< row; k++){for(intl=0; l{Console.Write("Please Input for "+ k +"th row and "+ l +"th column of first Matrix :: ");matrix1[k,l] =int.Parse(Console.ReadLine());}}for(intk = 0; k < row; k++){for(intl = 0; l < column; l++){Console.Write("Please Input for "+ k +"th row and "+ l +"th column of second Matrix :: ");matrix2[k, l] =int.Parse(Console.ReadLine());}}for(intk = 0; k < row; k++){for(intl = 0; l < column; l++){matrix3[k, l] = matrix1[k, l] + matrix2[k, l];}}Console.WriteLine("Sum of Matrix is following: ");for(intk = 0; k < row; k++){for(intl = 0; l < column; l++){Console.Write(matrix3[k, l] +" ");}Console.WriteLine();}Console.ReadKey();VulpesRank #55 · 29.2K reputationPosted Mar 3, 2014, 5:06 AM EST
Try this:
The output is:
Joe WilsonRank #631 · 3.8K reputationPosted Apr 17, 2014, 5:39 AM EDT
Joe Wilson
Joe WilsonRank #631 · 3.8K reputationPosted Apr 20, 2014, 2:43 AM EDT
Sincerely
Joe Wilson
VulpesRank #55 · 29.2K reputationPosted Apr 20, 2014, 6:36 AM EDT
Are you talking here about Abhay's answer or mine?
Mine certainly compiles and is a straightforward example of operating overloading in C#.
The '+' operator is overloaded in order to add two Matrix objects together and return a new Matrix whose elements are the sum of their corresponding elements.
As in the case of all operator overloads a static method is used in conjunction with the 'operator' keyword and the operator to be overloaded.
This method first makes sure that the sizes of the two Matrix objects to be added are the same as they can't be added otherwise and an exception is then thrown.
Joe WilsonRank #631 · 3.8K reputationPosted May 23, 2014, 10:45 AM EDT
I want to know some basic things about operator overloading,First.
Then, Compare my knowledge with your answers to my question.
Thanks.
VulpesRank #55 · 29.2K reputationPosted May 26, 2014, 3:34 AM EDT
http://www.codeproject.com/Articles/28974/An-Introduction-to-Operator-Overloading-in-C
http://www.codeproject.com/Articles/178309/Operator-Overloading-in-C-NET
http://www.codeproject.com/Articles/452727/A-Beginners-Tutorial-on-Operator-Overloading-in-Cs