Golang Program to add two given numbers

April 2, 2022, Learn eTutorial

For a better understanding of this example, we always recommend you to learn the basic topics of Golang programming listed below:

How to add two numbers in the Go Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to add two given numbers in the Go language. Here variables Num1, Num2 are holding the numbers that have to be added, and variable SUM for holding its sum value. The variables are added using the plus(+) operator. Given below are the steps which are used in the Go program. 


STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Declare the variable SUM for holding the sum

STEP 4: Initialise integer variable Num1, Num2 with values 20,45

STEP 5: Add two numbers and assign them to SUM as SUM=Num1+Num2

STEP 6: Print the sum using fmt.println()


Golang Source Code

                                          package main
import "fmt"

func main()  {

    var SUM int
    Num1 := 20
    Num2 := 45
    SUM = Num1 + Num2
    fmt.Println("The Sum of two numbers is = ", SUM)


The Sum of two numbers is = 65