GO Program to Swap Number Without Using Temporary Variables
In this program, user is asked to enter two numbers and program will swap two numbers without using third variable.
Example
package main
import "fmt"
func main(){
fmt.Print("Enter first number : ")
var first int
fmt.Scanln(&first)
fmt.Print("Enter second number : ")
var second int
fmt.Scanln(&second)
first = first-second
second = first+second
first = second-first
fmt.Println("First number :",first)
fmt.Println("Second number :",second)
}
Most Helpful This Week
Illustration of Sleeping Barber Problem in Golang
Example to compare Println vs Printf
Golang writing struct to JSON file
GO Program to Find Factorial of a Number
How to append struct member dynamically using Empty Interface?
How do you handle HTTP client server security in Go?
Panic: runtime error: index out of range error in Golang
Golang HTTP GET request with parameters
How to declare Interface Type in Go Programming Language
Convert Float32 to Float64 and Float64 to Float32