mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
762 B
51 lines
762 B
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
if len(os.Args) == 4 {
|
||
5 years ago
|
a, err := strconv.Atoi(os.Args[1])
|
||
5 years ago
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
5 years ago
|
b, err := strconv.Atoi(os.Args[3])
|
||
|
if err != nil {
|
||
5 years ago
|
return
|
||
|
}
|
||
5 years ago
|
operator := os.Args[2]
|
||
|
switch operator {
|
||
|
case "+":
|
||
|
result := a + b
|
||
5 years ago
|
if (result > a) == (b > 0) {
|
||
5 years ago
|
fmt.Println(result)
|
||
5 years ago
|
}
|
||
5 years ago
|
case "-":
|
||
|
result := a - b
|
||
5 years ago
|
if (result < a) == (b > 0) {
|
||
5 years ago
|
fmt.Println(result)
|
||
5 years ago
|
}
|
||
5 years ago
|
case "*":
|
||
|
result := a * b
|
||
5 years ago
|
if a == 0 || (result/a == b) {
|
||
5 years ago
|
fmt.Println(result)
|
||
|
}
|
||
|
case "/":
|
||
|
if b == 0 {
|
||
|
fmt.Println("No division by 0")
|
||
|
} else {
|
||
|
fmt.Println(a / b)
|
||
|
}
|
||
|
case "%":
|
||
|
if b == 0 {
|
||
|
fmt.Println("No modulo by 0")
|
||
|
} else {
|
||
|
fmt.Println(a % b)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|