Write a Scala program to input two matrices and print the addition of it


object Multiplication
{
def main(args : Array[String])
{
var mat1 = Array.ofDimInt
var mat2 = Array.ofDimInt
var add = Array.ofDimInt
var sum = 0

println("Enter no. of rows of 1st matrix element")
var r1 = scala.io.StdIn.readInt()
println("Enter no. of columns of 1st matrix element")
var c1 = scala.io.StdIn.readInt()

println("Enter 1st matrix elements")
for(i <- 1 to r1)
  for(j <- 1 to c1)
  {
    mat1(i)(j) = scala.io.StdIn.readInt()
  }
  
println("1st Matrix:")
for(i <- 1 to r1)
{
  for(j <- 1 to c1)
  {
    print(mat1(i)(j)+"\t")
  }
  print("\n\n")
}

 println("Enter no. of rows of 2nd matrix element")
var r2 = scala.io.StdIn.readInt()
println("Enter no. of columns of 2nd matrix element")
var c2 = scala.io.StdIn.readInt()

println("Enter 2nd matrix elements")
for(i <- 1 to r2)
  for(j <- 1 to c2)
  {
    mat2(i)(j) = scala.io.StdIn.readInt()
  }
  
println("2nd Matrix:")
for(i <- 1 to r2)
{
  for(j <- 1 to c2)
  {
    print(mat2(i)(j)+"\t")
  }
  print("\n\n")
}

for(i <- 1 to r1)
{
  for(j <- 1 to c2)
  {
    sum = 0
    add(i)(j) = 0
    sum=mat1(i)(j)+mat2(i)(j)
    add(i)(j) = sum
  }
}

println("Addition of matrices:")
for(i <- 1 to r1)
{
  for(j <- 1 to c2)
  {
    print(add(i)(j)+"\t")
  }
  println("\n")
}

}
}