Implementing Subtraction of Matrices Using 2D-Arrays:
using System; namespace MatrixSubtractionProgram { class Program { static void Main(string[] args) { //using 2D-ARRAYS int RowSize = 5, ColSize = 5; int[,] Matrix1 = new int[RowSize, ColSize]; int[,] Matrix2 = new int[RowSize, ColSize]; int[,] ResultMatrix = new int[RowSize, ColSize]; int i, j; try { Console.WriteLine("\n >>> PROGRAM To PRINT SUBTRACTION OF TWO MATRICES <<<"); Console.Write("\n Enter the Size of a Matrix N*N (For Example:3*3) : "); string s = Console.ReadLine(); string[] values = s.Split('*'); RowSize = int.Parse(values[0]); ColSize = int.Parse(values[1]); if (RowSize > 5 || ColSize > 5) //limiting the size of matrix { Console.BackgroundColor = ConsoleColor.DarkRed; //changing background color to red Console.WriteLine(" The Size Of Matrix should Be in Less Than 5 (limiting size of array)"); System.Console.ResetColor(); ///resetting color Console.WriteLine("\n\n\t Press Enter key to exit...."); Console.ReadKey(); return; } else { //Initializing all the elements to zero for (i = 0; i < RowSize; i++) { for (j = 0; j < ColSize; j++) { Matrix1[i, j] = 0; Matrix2[i, j] = 0; } } //Reading elements of Matrix1 Console.WriteLine("\n Enter the elements of Matrix1({0}*{1})", RowSize, ColSize); for (i = 0; i < RowSize; i++) { for (j = 0; j < ColSize; j++) { Console.Write(" Matrix1[{0},{1}] : ", i, j); Matrix1[i, j] = Convert.ToInt32(Console.ReadLine()); } } //Reading elements of Matrix2 Console.WriteLine("\n Enter the elements of Matrix2({0}*{1})", RowSize, ColSize); for (i = 0; i < RowSize; i++) { for (j = 0; j < ColSize; j++) { Console.Write(" Matrix2[{0},{1}] : ", i, j); Matrix2[i, j] = Convert.ToInt32(Console.ReadLine()); } } //calculating ResultMatrix, by SUBTRACTING Matrix2 FROM Matrix1 for (i = 0; i < RowSize; i++) { for (j = 0; j < ColSize; j++) { ResultMatrix[i, j] = Matrix1[i, j] - Matrix2[i, j]; } } //Printing Result Matrix Console.Write("\n\n\t*** Result Matrix ***\n\n\t"); for (i = 0; i < RowSize; i++) { for (j = 0; j < ColSize; j++) { if (ResultMatrix[i, j] < 10) { //Making number as 01,02,etc,. Console.Write(" 0" + Convert.ToString(ResultMatrix[i, j])); } else { Console.Write(" " + Convert.ToString(ResultMatrix[i, j])); } if (j == ColSize - 1) { Console.Write("\n\t"); } } } } } catch //to catch exceptions,suppose string entered as aRowSize or Colsize of matrix { Console.BackgroundColor = ConsoleColor.DarkRed; Console.WriteLine("WARNING:only Number are allowed, Enter Correct Input"); Console.ResetColor(); } Console.WriteLine("\n\n\t Press Enter key to exit...."); Console.ReadLine(); } } }
In the above program the code can be shortened by reducing the number of for loops or by using functions, but for making it easier to understand by the beginners, the program is made as simple as possible. Some of the different Sample Outputs of the above program are shown below:
Output:
For C Program :
Great Explanation..Very good Example..
ReplyDeleteOnline CSharp
Training
C Sharp Training
Online C# Training from India
C Sharp Training in Chennai
C# Training
Online Dot Net Training
.net online Training
ASP NET Training
Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training in chennai velachery | dot net training institute in velachery
ReplyDeleteIt is really a great work and the way in which u r sharing the knowledge is excellent.
ReplyDeleteThanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article.. dot net training and placement in chennai | best dot net training in chennai
to awesome information it pretty good about c# dot net.
ReplyDeletebest training institute in chennai
Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
ReplyDeleteDigital Marketing online training
full stack developer training in pune
full stack developer training in annanagar
full stack developer training in tambaram
full stack developer training in velachery
Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
ReplyDeletepython training institute in chennai
python training in chennai
python training in chennai
Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
ReplyDeleteBlueprism training in annanagar
Blueprism training in velachery
Blueprism training in marathahalli
From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
ReplyDeleteData science training in tambaram
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
Data Science training in marathahalli
Data Science training in btm
You blog post is just completely quality and informative. Many new facts and information which I have not heard about before. Keep sharing more blog posts.
ReplyDeletejava training in chennai | java training in bangalore
java online training | java training in pune
I found this informative and interesting blog so i think so its very useful and knowledge able.I would like to thank you for the efforts you have made in writing this article.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Java Script online training
Share Point online training
It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
ReplyDeleteJava Training in Chennai |Best Java Training in Chennai
C C++ Training in Chennai |Best C C++ Training Institute in Chennai
Data science Course Training in Chennai |Best Data Science Training Institute in Chennai
RPA Course Training in Chennai |Best RPA Training Institute in Chennai
AWS Course Training in Chennai |Best AWS Training Institute in Chennai
Devops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai
inplant training in chennai
ReplyDeleteinplant training in chennai
inplant training in chennai for it.php
chile web hosting
colombia web hosting
croatia web hosting
cyprus web hosting
bahrain web hosting
india web hosting
iran web hosting
Thank you for posting informative insights, I think we have got some more information to share with! Do check out
ReplyDeleteoracle dba training in chennai and let us know your thoughts. Let’s have great learning!
Sharing the same interest, Infycle feels so happy to share our detailed information about all these courses with you all! Big data training in chennai & get to know everything you want to about software trainings.
ReplyDeleteSearching for the Oracle Training in Chennai? Then come to Infycle for the best software training in Chennai. Infycle Technologies is one of the best Oracle training institute in Chennai, which offers various programs in Oracle such as Oracle PLSQL, Oracle DBA, etc., in complete hands-on practical training from professionals in the field. Along with that, the interviews will be arranged for the candidates and 200% placement assurance will be given here. To have the words above in your life, call 7502633633 to Infycle Technologies and grab a free demo to know more.Top Oracle DBA Training in Chennai
ReplyDeleteThanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.
ReplyDeleteRobots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids
Data Science training in Chennai | Infycle Technologies
ReplyDeleteInfycle Technologies is the best software training center in Chennai, providing amazing Data Science training in Chennai which will be realistic and taught by industry experts. Aside from practical training preparation, mock interviews will be arranged for students so that they can confidently face the interviews. All of this will be packed up by full placement assurance with the best salary package from top companies. For having a free demo session, call 7502633633.
Best training center in Chennai
Infycle Technologies, the No.1 software training institute in Chennai offers the No.1 Big Data Hadoop Training in Chennai | Infycle Technologies for students, freshers, and tech professionals. Infycle also offers other professional courses such as DevOps, Artificial Intelligence, Cyber Security, Python, Oracle, Java, Power BI, Selenium Testing, Digital Marketing, Data Science, etc., which will be trained with 200% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7502633633 to get more info and a free demo.
ReplyDeleteInfycle Technologies, the best software training institute cum placement center in Chennai offers the best Digital Marketing course in Chennai for freshers, students, and tech professionals at the best offers. In addition to the Digital Marketing Training, other in-demand courses such as AWS, DevOps, Data Science, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.Best Digital Marketing Course in Chennai | Infycle Technologies
ReplyDeleteSmart move for your career is Choosing to do Oracle Course in Chennai at Infycle!! Do you know why this name is chosen for Infycle. Infycle where the place we offered Infinity of Oracle.
ReplyDeleteYes!!! But not only Oracle, More than 20+ courses are offered here 5000+ students are placed in top MNC’s Company with good salary packages. For admission 7502633633. Oracle Course in Chennai | Infycle Technologies