「Go言語」加算,減算,乗算,除算など演算子のサンプル

書式
var 変数名 int = xxx
使用例

package main

import "fmt"

func main() {

   var a int = 31
   var b int = 15
   var c int

   c = a + b
   fmt.Printf("line 1 - c value is  %d\n", c )
   c = a - b
   fmt.Printf("line 2 - c value is  %d\n", c )
   c = a * b
   fmt.Printf("line 3 - c value is  %d\n", c )
   c = a / b
   fmt.Printf("line 4 - c value is  %d\n", c )
   c = a % b
   fmt.Printf("line 5 - c value is  %d\n", c )
   a++
   fmt.Printf("line 5 - a value is  %d\n", a )
   a=31   
   a--
   fmt.Printf("line 7 - a value is  %d\n", a )
}

実行結果
>go run test.go
line 1 – c value is 46
line 2 – c value is 16
line 3 – c value is 465
line 4 – c value is 2
line 5 – c value is 1
line 5 – a value is 32
line 7 – a value is 30

Go言語

Posted by arkgame