Go Arithmetic Operators Swap Number Without Using Temporary Variables

Description

Go Arithmetic Operators Swap Number Without Using Temporary Variables

package main/*from w  ww  .  j  a v a  2  s .c  o  m*/

import "fmt"

func main(){
    
    var first int
    first = 9

    var second int
    second = 7

    fmt.Println("First number :",first)
    fmt.Println("Second number :",second)

    first = first-second
    second = first+second
    first = second-first
    
    fmt.Println("First number :",first)
    fmt.Println("Second number :",second)
}



PreviousNext

Related