Advertisement
Spocoman

06. Operations Between Numbers

Sep 18th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.03 KB | None | 0 0
  1. package main
  2. import "fmt"
  3.  
  4. func main() {
  5.     var num1, num2 int
  6.     fmt.Scanln(&num1)
  7.     fmt.Scanln(&num2)
  8.    
  9.     var symbol string
  10.     fmt.Scanln(&symbol)
  11.  
  12.     var number = ""
  13.  
  14.     if (symbol == "+" || symbol == "-" || symbol == "*") {
  15.         var sum = 0
  16.         if (symbol == "+") {
  17.             sum = num1 + num2
  18.         } else if (symbol == "-") {
  19.             sum = num1 - num2
  20.         } else {
  21.             sum = num1 * num2
  22.         }
  23.        
  24.         if (sum % 2 == 0) {
  25.             number = "even"
  26.         } else {
  27.             number = "odd"
  28.         }
  29.         fmt.Printf("%d %s %d = %d - %s\n", num1, symbol, num2, sum, number)
  30.     } else {
  31.         if (num2 == 0) {
  32.             fmt.Printf("Cannot divide %d by zero", num1)
  33.         } else {
  34.             if (symbol == "/") {
  35.                 fmt.Printf("%d / %d = %.2f\n", num1, num2, float64(num1) / float64(num2))
  36.             } else if (symbol == "%") {
  37.                 fmt.Printf("%d %% %d = %d\n", num1, num2, num1 % num2)
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement