
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to Illustrate Upper Triangular Matrix
For the upper triangular matrix, set all the elements below the main diagonal to zero.
Set the following condition −
if (i <= j) Console.Write(A[i, j] + "\t"); else Console.Write("0\t");
Above condition will set 0 to the matrix elements below the main diagonal.
Example
You can try to run the following code to display an upper 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 elements: "); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { A[i, j] = Convert.ToInt16(Console.ReadLine()); } } Console.WriteLine("
Upper 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 elements: Upper Triangular Matrix
- Related Articles
- C# Program to Illustrate Lower Triangular Matrix
- Java Program to display upper triangular matrix
- Golang Program To Display Upper Triangular Matrix
- Swift Program to Display Upper Triangular Matrix
- Program to check if matrix is upper triangular in C++
- Program to print Lower triangular and Upper triangular matrix of an array in C
- How to replace upper triangular matrix with lower triangular matrix and vice versa in R?
- How to create an upper triangular matrix using vector elements in R?
- Swift Program to Display Lower Triangular Matrix
- How to find the row and column index for upper triangular matrix elements in R?
- Program to check if matrix is lower triangular in C++
- Print lower triangular matrix pattern from given array in C Program.
- How to solve triangular matrix equations using Python SciPy?
- How to create a heatmap for lower triangular matrix in R?
- Check if the matrix is lower triangular using Python

Advertisements