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.
50 lines
762 B
50 lines
762 B
package main |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
"strconv" |
|
) |
|
|
|
func main() { |
|
if len(os.Args) == 4 { |
|
a, err := strconv.Atoi(os.Args[1]) |
|
if err != nil { |
|
return |
|
} |
|
b, err := strconv.Atoi(os.Args[3]) |
|
if err != nil { |
|
return |
|
} |
|
operator := os.Args[2] |
|
switch operator { |
|
case "+": |
|
result := a + b |
|
if (result > a) == (b > 0) { |
|
fmt.Println(result) |
|
} |
|
case "-": |
|
result := a - b |
|
if (result < a) == (b > 0) { |
|
fmt.Println(result) |
|
} |
|
case "*": |
|
result := a * b |
|
if a == 0 || (result/a == b) { |
|
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) |
|
} |
|
} |
|
} |
|
}
|
|
|