WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - Arithmetic Operators


mathematics operators supported by means of Go language. Assume variable A holds 15 and variable B holds 30 then

Operator Description Example
+ Adds two operands A + B offers 45
- Subtracts second operand from the first A - B gives -15
* Multiplies each operands A * B offers 450
/ Divides the numerator by using the denominator. B / A offers 2
% Modulus operator; offers the remainder after an integer division. B % A gives 0
++ Increment operator. It will increase the integer value by one. A++ offers 16
-- Decrement operator. It decreases the integer value through one. A-- offers 14

Example


package deal fundamental

import "fmt"

func principal() 

   var a int = 15
   var b int = 30
   var c int

   c = a + b
   fmt.Printf("Line 1 - Value of c is %dn", c )
   
   c = a - b
   fmt.Printf("Line 2 - Value of c is %dn", c )
   
   c = a * b
   fmt.Printf("Line 3 - Value of c is %dn", c )
   
   c = a / b
   fmt.Printf("Line 4 - Value of c is %dn", c )
   
   c = a % b
   fmt.Printf("Line 5 - Value of c is %dn", c )
   
   a++
   fmt.Printf("Line 6 - Value of a is %dn", a )
   
   a--
   fmt.Printf("Line 7 - Value of a is %dn", a )

When you compile and execute the above application, it produces the following result

$pass run important.Move
Line 1 - Value of c is 45
Line 2 - Value of c is -15
Line three - Value of c is 450
Line 4 - Value of c is 0
Line 5 - Value of c is 15
Line 6 - Value of a is sixteen
Line 7 - Value of a is 15