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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted May 26, 2014, 7:34 AM
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
Joe WilsonPosted May 23, 2014, 2:45 PM
I want to know some basic things about operator overloading,First.
Then, Compare my knowledge with your answers to my question.
Thanks.
VulpesPosted Apr 20, 2014, 10:36 AM
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 WilsonPosted Apr 20, 2014, 6:43 AM
Sincerely
Joe Wilson
Joe WilsonPosted Apr 17, 2014, 9:39 AM
Joe Wilson
VulpesPosted Mar 3, 2014, 10:06 AM
Try this:
The output is:
Abhay ShankerPosted Mar 3, 2014, 9:50 AM
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();