GO Program to add two given numbers

How to add two given numbers

Here we are explaining how to add two numbers in the Go program. We can use the built-in function fmt.println() to print anything. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.


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 N1, N2 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 N1, N2 with values 20,45

STEP 5: Add two numbers and assign them to SUM as SUM=N1+N2

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


GO Source Code

                                          package main
import "fmt"

func main()  {

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


The Sum of two numbers is = 65