Arithmetic/Integer: Difference between revisions

→‎{{header|Go}}: task conformance
(Added DWScript)
(→‎{{header|Go}}: task conformance)
Line 744:
 
=={{header|Go}}==
<lang go>importpackage "fmt"main
 
func arithmetic(a int, b int) {
import "fmt"
fmt.Printf("a+b = %d\n", a+b)
 
fmt.Printf("a-b = %d\n", a-b)
func main() {
fmt.Printf("a*b = %d\n", a*b)
var a, b int
fmt.Printf("a/b = %d\n", a/b) // truncates towards 0
fmt.Print("enter two integers: ")
fmt.Printf("a%%b = %d\n", a%b) // same sign as first operand
fmt.Scanln(&a, &b)
fmt.Printf("a%d +b %d = %d\n", a, b, a+b)
fmt.Printf("a%d -b %d = %d\n", a, b, a-b)
fmt.Printf("a%d *b %d = %d\n", a, b, a*b)
fmt.Printf("a%d /b %d = %d\n", a, b, a/b) // truncates towards 0
fmt.Printf("a%d %b% %d = %d\n", a, b, a%b) // same sign as first operand
// no exponentiation operator
}</lang>
Example run:
<pre>
enter two integers: -5 3
-5 + 3 = -2
-5 - 3 = -8
-5 * 3 = -15
-5 / 3 = -1
-5 % 3 = -2
</pre>
 
=={{header|Groovy}}==
1,707

edits