matrix is upper triangular or not
Q4 Write a program to check if the matrix is upper triangular or not
object UpperTrang {
def main(args: Array[String]): Unit =
{
var A=Array.ofDimInt
var m= scala.io.StdIn.readInt()
var n = scala.io.StdIn.readInt()
for (i <- 0 to m-1)
{
for (j <- 0 to n-1)
{
A(i)(j)=scala.io.StdIn.readInt()
}
}
println("The given matrix is ");
for (i <- 0 to m-1)
{
for (j <- 0 to n-1)
{
print(A(i)(j)+"\t");
}
println(" ");
}
var isUpper = 1;
for(row<-0 to m-1)
for(col<-0 to n-1)
if(col<row && A(row)(col)!=0)
isUpper = 0;
if(isUpper==1)
{
println("This is a Upper triangular matrix")
for(row<-0 to m-1)
for(col<-0 to n-1)
if(A(row)(col)!= 0)
{
print(A(row)(col) +"");
}
}
else
{
println("This is Not a Upper triangular matrix.");
}
}
}