Golang to Find the GCD and LCM of Two Integers

Golang to Find the GCD and LCM of Two Integers

Today, We want to share with you Golang to Find the GCD and LCM of Two Integers.In this post we will show you GO Program to Find the GCD and LCM of Two Integers, hear for Find GCD of Two Numbers Using Golang Recursion we will give you demo and example for implement.In this post, we will learn about GO program to find gcd of two numbers using recursion with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

Snippet Contents

Golang to Find the GCD and LCM of Two Integers

There are the Following The simple About Golang to Find the GCD and LCM of Two Integers Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to find gcd of two numbers using GO Program, so the Program To Find HCF In GO for this example is following below.

Example of Switch in ….. Case GO Program to calculate the maths formula LCM and GCD of two any integers. The simple as well as used to For…Loop used as a While Loop in this Golang example below.

Golang Program to find LCM and GCD of two numbers

package main
import "fmt"
 
func lcm(first_tmp int,second_tmp int) { 
    var lcmnum int =1
    if(first_tmp>second_tmp)    {
        lcmnum=first_tmp
    }else{
        lcmnum=second_tmp
    }
    for {        
        if(lcmnum%first_tmp==0 && lcmnum%second_tmp==0) { 
            fmt.Printf("LCM of %d and %d is %d",first_tmp,second_tmp,lcmnum)            
            break
        }
        lcmnum++
    }
    return
}
 
func gcd(first_tmp int,second_tmp int){
       var gcdnum int 
    for i := 1; i <=first_tmp && i <=second_tmp ; i++ {
            if(first_tmp%i==0 && second_tmp%i==0) {
                gcdnum=i
            } 
        }
        fmt.Printf("GCD of %d and %d is %d",first_tmp,second_tmp,gcdnum)
    return
}  
 
 
func main() {
    var first_no,second_no,action int
    fmt.Println("Please Enter Your Any two positive integers : ")
    fmt.Scanln(&first_no)
    fmt.Scanln(&second_no)
 
    fmt.Println("Enter 1 for LCM and 2 for GCD")
    fmt.Scanln(&action)
      
    switch action {
        case 1:
            lcm(first_no,second_no)
        case 2:
            gcd(first_no,second_no)
    }
}

here above Go Program Example To Use of Switch Case.

Pattern programs in GO Example
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Golang to Find the GCD and LCM of Two Integers.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Check Armstrong Number in GO Program
  2.   how to get last inserted id in laravel 6?
  3.   GO Program to Display Fibonacci Sequence
  4.   Laravel All Where eloquent methods with Examples
  5.   jQuery Ajax Image Upload without Page Refresh using PHP
  6.   Add Edit And Delete Records Using jQuery Ajax PHP And MySQL
  7.   Laravel 6 WhereNotIn Query Example
  8.   Smooth Scroll to Top with jQuery
  9.   Go Program to Print Pyramid Pattern using numbers
  10.   Pattern programs in GO Example