Go: Two sum array

 

 

 

package main

import (
  "fmt"
)

func main(){
  var arrayOne = [...]int{9,1,5,4,7}
  var desiredNumber = 10
  for i:=0; i<len(arrayOne); i++{
    if (i != (len(arrayOne) - 1)){
      if((arrayOne[i]+arrayOne[i+1]) == desiredNumber ){
        fmt.Printf("Result %d %d",i, i+1)
      }
    }
  }
}

 













Leave a Reply

Your email address will not be published. Required fields are marked *