Go language program to find largest number from given 2 numbers

Views: 140   

Following program shows you how to find largest number from given 2 numbers.
In this program we get inputs from user and shows largest number from given two numbers using if condition

package main

import "fmt"

func main() {

  var input1 int
  var input2 int
  fmt.Println("Enter first number:")
  fmt.Scanf("%d", &input1)
  fmt.Println("Enter second number:")
  fmt.Scanf("%d", &input2)
  if (input1 == input2) {
    fmt.Println(input1 , " is equal to " , input2)
  } else if (input1 > input2) {
    fmt.Println(input1 , " is larger than " , input2)
  } else {
    fmt.Println(input1 , " is lesser than " , input2)
  }
}

Output:

Example1:

Enter first number:
 15
Enter second number:
 15
15  is equal to  15

Example2:

Enter first number:
 22
Enter second number:
 15
22  is larger than  15

Example3:

Enter first number:
 35
Enter second number:
 55
35  is lesser than  55
On By