- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to Illustrate Lower Triangular Matrix
For the lower triangular matrix, set all the elements above the main diagonal to zero.
Set the following condition −
if (i >= j) Console.Write(A[i, j] + "\t"); else Console.Write("0\t");
Example
You can try to run the following code to display a lower triangular matrix.
using System; using System.Linq; class Demo { static void Main() { int m, n, i, j; Console.Write("Enter number of rows and columns of the matrix "); m = Convert.ToInt16(Console.ReadLine()); n = Convert.ToInt16(Console.ReadLine()); int[,] A = new int[10, 10]; Console.Write("
Enter matrix elements: "); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { A[i, j] = Convert.ToInt16(Console.ReadLine()); } } Console.Clear(); Console.WriteLine("
Lower Triangular Matrix "); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { Console.Write(A[i, j] + "\t"); } Console.WriteLine(); } for (i = 0; i < m; i++) { Console.Write("
"); for (j = 0; j < 3; j++) { if (i >= j) Console.Write(A[i, j] + "\t"); else Console.Write("0\t"); } } Console.ReadLine(); } }
Output
Enter number of rows and columns of the matrix Enter matrix elements: Lower Triangular Matrix
Advertisements