Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Go Program to find Largest of Two Numbers

by suresh

This Go Program to find Largest of Two Numbers uses the If Else statement. The if condition checks whether num1 is greater than num2, and if it is true, num1 is largest. Otherwise, it prints the else statement.

package main

import "fmt"

func main()  {
    var num1, num2 int
    fmt.Print("Enter the First Number to find Largest of Two  = ")
    fmt.Scanln(&num1)

    fmt.Print("Enter the Second Number to find Largest of Two = ")
    fmt.Scanln(&num2)

    if num1 > num2 {
        fmt.Println("The Largest amoung two  = ", num1 )
    } else {
        fmt.Println("The Largest amoung two  = ", num2 )
    }
}
Go Program to find Largest of Two Numbers 1

Go Program to find Largest of Two Numbers.

This Golang Program uses the Else If statement to calculate the Largest of Two Numbers. 

  • if num1 > num2 – Check num1 is greater than num2. If True, num1 is largest.
  • else if num2 > num1 – check num2 is greater than num1. If true, num2 is largest.
  • If both the above conditions fail, they both are equal.
package main

import "fmt"

func main()  {
    var num1, num2 int
    fmt.Print("Enter the First Number to find Largest of Two  = ")
    fmt.Scanln(&num1)

    fmt.Print("Enter the Second Number to find Largest of Two = ")
    fmt.Scanln(&num2)

    if num1 > num2 {
        fmt.Println("The Largest amoung two  = ", num1 )
    } else if num2 > num1 {
        fmt.Println("The Largest amoung two  = ", num2 )
    } else {
        fmt.Println("Both of them are Equal")
    }
}
Golang Program to find Largest of Two Numbers 2

In this Golang program, we used the switch case to print the largest among two numbers.

package main

import "fmt"

func main() {
    var num1, num2 int
    fmt.Print("Enter the First Number to find Largest of Two  = ")
    fmt.Scanln(&num1)

    fmt.Print("Enter the Second Number to find Largest of Two = ")
    fmt.Scanln(&num2)

    switch {
    case num1 > num2:
        fmt.Println("The Largest amoung two  = ", num1)
    case num1 < num2:
        fmt.Println("The Largest amoung two  = ", num2)
    default:
        fmt.Println("Both are Equal")
    }
}
Go Program to find Largest of Two Numbers 3

Placed Under: Go Examples

  • Golang Hello World Program
  • Go Add Two Number
  • Go Compound Interest
  • Go Count Digits in a Number
  • Go Cube of a Number
  • Go Even or Odd
  • Go Largest of Three Numbers
  • Go Reverse Natural Numbers
  • Go Multiplication Table
  • Go Number divisible by 5 and 11
  • Go Positive or Negative
  • Go Power of a Number
  • Go Print Natural Numbers
  • Go Profit or Loss
  • Go Print 1 to 100 without loop
  • Go Program to Print 1 to 100
  • Go Product of Digits in a Number
  • Go Palindrome Number Program
  • Go Print Even Numbers
  • Go Print Odd Numbers
  • Go Factors of a Number
  • Go Perfect Number
  • Go Prime Number
  • Go Reverse a Number
  • Go Simple Interest
  • Go Square of a Number
  • Go Square root of a Number
  • Go Sum of Digits in a Number
  • Go Sum & Avg of Natural Nums
  • Go Sum of Even Numbers
  • Go Sum of Odd Numbers
  • Go Sum of Even and Odd
  • Go Sphere Vol & Surface Area
  • Go Cylinder Vol & Surface Area
  • Go Cuboid Vol & Surface Area
  • Go Cube Volume & Surface Area
  • Go Cone Volume & Surface Area

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy