What is upper triangular matrix?
A matrix where all elements below the left diagonal are zero is called upper triangular matrix.
import java.util.*;
class UTMatrix
{
int arr[][];
int i,j,c,n;
Scanner sc=new Scanner(System.in);
public void show()
{
System.out.print("\nEnter the size of array:");
n=sc.nextInt();
arr=new int[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print("\nValue:");
arr[i][j]=sc.nextInt();
}
}
System.out.print("\nMatrix Values\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(arr[i][j]!=0 && j<i)
{
c=1;
break;
}
}
}
if(c==0)
System.out.print("\nThis is an upper traingular Matrix");
else
System.out.print("\nThis is not an upper traingular Matrix");
}
}
class UTMatrix
{
int arr[][];
int i,j,c,n;
Scanner sc=new Scanner(System.in);
public void show()
{
System.out.print("\nEnter the size of array:");
n=sc.nextInt();
arr=new int[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print("\nValue:");
arr[i][j]=sc.nextInt();
}
}
System.out.print("\nMatrix Values\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(arr[i][j]!=0 && j<i)
{
c=1;
break;
}
}
}
if(c==0)
System.out.print("\nThis is an upper traingular Matrix");
else
System.out.print("\nThis is not an upper traingular Matrix");
}
}
No comments:
Post a Comment