Go for statement calculate LCM

Description

Go for statement calculate LCM

package main/*w w  w.jav  a  2  s  .c o  m*/
import "fmt"

func lcm(temp1 int,temp2 int) { 
    var lcmnum int =1
    if(temp1>temp2)    {
        lcmnum=temp1
    }else{
        lcmnum=temp2
    }
    for {        
        if(lcmnum%temp1==0 && lcmnum%temp2==0) { 
            fmt.Printf("LCM of %d and %d is %d",temp1,temp2,lcmnum)            
            break
        }
        lcmnum++
    }
    return // Return without any value
}

func main() {
    var n1,n2 int
    n1 = 48
    n2 = 24

    lcm(n1,n2)
}



PreviousNext

Related