Social Items

Go Program To Addition Matrices (Golang)

Go Program To Addition Two Matrices - in this post we will learn how to create a program to calculate the addition of two matrices in Go programming language.

Matrix is a set of numbers arranged in rows (vertical) and columns (horizontal) can be referred to as a two-dimensional array. matrix addition have terms that are the order of the matrix must be equal, or in other words, the two matrices must have the number of rows and columns are the same.

Source Code :


 
package main  
   
import (  
  "fmt"  
)  
  
func main() {  
  
  var i, j, m, n int  
  var matriksA [10][10]int  
  var matriksB [10][10]int  
  
  fmt.Print("Enter the number of rows of a matrix: ")  
  fmt.Scanln(&m)  
  fmt.Print("Enter the number of columns of the matrix: ")  
  fmt.Scanln(&n)  
  
  fmt.Println("Enter the Matrix A element: ")  
  for i = 0; i < m; i++ {  
    for j = 0; j < n; j++ {  
      fmt.Scan(&matriksA[i][j])  
    }  
  }  
  
  fmt.Println("Enter the Matrix B element: ")  
  for i = 0; i < m; i++ {  
    for j = 0; j < n; j++ {  
      fmt.Scan(&matriksB[i][j])  
    }  
  }  
  
  fmt.Println("The results addition of matrix A & B: ")  
  for i = 0; i < m; i++ {  
    for j = 0; j < n; j++ {  
      fmt.Print(matriksA[i][j]+matriksB[i][j], "\t")  
    }  
    fmt.Println()  
  }  
}

Save the source code with the name of additionmatrices.go, but adjust wrote with a file name that chills and don't forget the extension should .go

Compile & Run :

Here's how to compile source code manually:

$ go build additionmatrices.go
$ ./additionmatrices
You can run without having to compile it:

$ go run additionmatrices.go

The Output of Program :


The Output of Program Addition Two Matrices (Golang)
The Output of Program Addition Two Matrices (Golang)

Conclusion :

From the results of the matrix addition program can be run without any error and display the results of the addition of matrices A and matrix B.

Video :

Go Program To Addition Two Matrices (Golang)

Go Program To Addition Matrices (Golang)

Go Program To Addition Two Matrices - in this post we will learn how to create a program to calculate the addition of two matrices in Go programming language.

Matrix is a set of numbers arranged in rows (vertical) and columns (horizontal) can be referred to as a two-dimensional array. matrix addition have terms that are the order of the matrix must be equal, or in other words, the two matrices must have the number of rows and columns are the same.

Source Code :


 
package main  
   
import (  
  "fmt"  
)  
  
func main() {  
  
  var i, j, m, n int  
  var matriksA [10][10]int  
  var matriksB [10][10]int  
  
  fmt.Print("Enter the number of rows of a matrix: ")  
  fmt.Scanln(&m)  
  fmt.Print("Enter the number of columns of the matrix: ")  
  fmt.Scanln(&n)  
  
  fmt.Println("Enter the Matrix A element: ")  
  for i = 0; i < m; i++ {  
    for j = 0; j < n; j++ {  
      fmt.Scan(&matriksA[i][j])  
    }  
  }  
  
  fmt.Println("Enter the Matrix B element: ")  
  for i = 0; i < m; i++ {  
    for j = 0; j < n; j++ {  
      fmt.Scan(&matriksB[i][j])  
    }  
  }  
  
  fmt.Println("The results addition of matrix A & B: ")  
  for i = 0; i < m; i++ {  
    for j = 0; j < n; j++ {  
      fmt.Print(matriksA[i][j]+matriksB[i][j], "\t")  
    }  
    fmt.Println()  
  }  
}

Save the source code with the name of additionmatrices.go, but adjust wrote with a file name that chills and don't forget the extension should .go

Compile & Run :

Here's how to compile source code manually:

$ go build additionmatrices.go
$ ./additionmatrices
You can run without having to compile it:

$ go run additionmatrices.go

The Output of Program :


The Output of Program Addition Two Matrices (Golang)
The Output of Program Addition Two Matrices (Golang)

Conclusion :

From the results of the matrix addition program can be run without any error and display the results of the addition of matrices A and matrix B.

Video :

Subscribe Our Newsletter