Go Function Question 1

Introduction

Function that halves an integer and returns true if even value or false if odd value:

func half(x int) (int, bool) { 
  return x/2, x%2==0 
} 
     package main 

     import "fmt" 

func half(x int) (int, bool) { 
  return x/2, x%2==0 
} 
     /*from ww  w  .  j  av  a2  s. co  m*/
     func main() { 
       var x, b = half(4)
       fmt.Println(x, b);
            
       x, b = half(5)
       fmt.Println(x, b);
     }



PreviousNext

Related