Found 1082 Articles for Go Programming

Write a Golang program to search an element in an array

Kiran P
Updated on 04-Feb-2021 10:54:20

281 Views

Definition: A number is that is greater than 2 and divisible only by itself and 1.Examples: Prime numbers are 2, 3, 5, 7, 11, 13, 113, 119, ..., etc.Approach to solve this problemStep 1: Find square root of the given number, sq_root = √numStep 2: If the given number is divisible by a number that belongs to [2, sq_root], then print “Non Prime Number”Step 3: If not divisible by any number, then print “Prime Number”ProgramLive Demopackage main import (    "fmt"    "math" ) func checkPrimeNumber(num int) {    if num < 2 {       fmt.Println("Number must be greater than 2.")       return    }    sq_root := int(math.Sqrt(float64(num)))    for i:=2; i

Bubble Sort in Go Lang

Dev Prakash Sharma
Updated on 05-Feb-2021 11:53:00

5K+ Views

Bubble Sort is a sorting algorithm that works by swapping the elements that are in the wrong order. In multiple passes, it checks if the adjacent elements are in the right order (increasing) or not.The Time Complexity of the Bubble Sort is O(n^2) since it takes two nested loops to check the adjacent element.For example, let’s take the following unsorted array −22 15 11 45 13Bubble Sort Algorithm first traverses the whole array and then in another loop checks if the adjacent elements are in order or not.Thus, after sorting the elements will be, 11 13 15 22 45AlgorithmIn two ... Read More

Write a Golang program to check whether a given number is prime number or not

Kiran P
Updated on 04-Feb-2021 10:52:02

3K+ Views

Definition: A number is that is greater than 2 and divisible only by itself and 1.Examples: Prime numbers are 2, 3, 5, 7, 11, 13, 113, 119, ..., etc.Approach to solve this problemStep 1: Find square root of the given number, sq_root = √numStep 2: If the given number is divisible by a number that belongs to [2, sq_root], then print “Non Prime Number”Step 3: If not divisible by any number, then print “Prime Number”ProgramLive Demopackage main import (    "fmt"    "math" ) func checkPrimeNumber(num int) {    if num < 2 {       fmt.Println("Number must be greater than 2.")       return    }    sq_root := int(math.Sqrt(float64(num)))    for i:=2; i

Write a Golang program to find the element with the minimum value in an array

Kiran P
Updated on 04-Feb-2021 10:52:24

710 Views

ExamplesA1 = [2, 4, 6, 7, 8, 10, 3, 6, 0, 1]; Minimum number is 0;A2 = [12, 14, 16, 17, 18, 110, 13, 16, 10, 11]; Minimum number is 10;Approach to solve this problemStep 1: Consider the number at the 0th index as the minimum number, min_num = A[0].Step 2: Compare min_num with every number in the given array, while iterating.Step 3: If a number is smaller than min_num, then assign that number to min_num.Step 4: At the end of iteration, return min_num;ProgramLive Demopackage main import "fmt" func findMinElement(arr []int) int {    min_num := arr[0]    for i:=0; i

Write a program in Go language to find the element with the maximum value in an array

Kiran P
Updated on 04-Feb-2021 10:52:45

568 Views

ExamplesA1 = [2, 4, 6, 7, 8, 10, 3, 6, 0, 1]; Maximum number is 10A2 = [12, 14, 16, 17, 18, 110, 13, 16, 10, 11]; Maximum number is 110Approach to solve this problemStep 1: Consider the number at the 0th index as the maximum number, max_num = A[0]Step 2: Compare max_num with every number in the given array, while iterating.Step 3: If a number is greater than max_num, then assign that number to max_num;Step 4: At the end of iteration, return max_num;ProgramLive Demopackage main import "fmt" func findMaxElement(arr []int) int {    max_num := arr[0]    for i:=0; i ... Read More

How To Install Go (Golang) 1.7 on CentOS 7

Sharon Christine
Updated on 20-Jan-2020 13:13:17

200 Views

In this article, we will learn about how to install and configure Go (golang) which is developed by Google and its open source programming language. It’s a simple, efficient and reliable programming language for development with minimalist.PrerequisitesA CentOS machine installed.A non-root user with Sudo permission on the CentOS machine.Downloading and Installing the GOThe Go (golang) is not up to date on the CentOS repository, so we will manually download and install the package directly from the Go lang website and also make sure that we have the latest version which is compatible with our system architecture.Let’s move to the writable ... Read More

How to Install and Use Docker on Ubuntu 16.04

Sharon Christine
Updated on 20-Jan-2020 11:36:54

220 Views

Docker is an open-source project that automates the deployment of application inside the software container. The container allows the developer to package up all project resources such as libraries, dependencies, assets etc. Docker is written in Go Programming language and is developed by Dotcloud. It is basically a container engine which uses the Linux Kernel features like namespaces and control groups to create containers on top of an operating system and automates the application deployment on the container.Installing DockerBefore install Docker, it should required updated packages. To update the packages, use the following command –$ sudo apt-get updateUse the following ... Read More

Best Way to Install Go 1.7 on Ubuntu

Sharon Christine
Updated on 20-Jan-2020 07:05:18

439 Views

Go is a free and open source programming language created by Google in 2007. It supplies convenient to construct simple, nontoxic, and effective programs. This language is designed for writing on servers. This article explains about ‘How to install Go 1.7 on Ubuntu’Installing Go Programming languageTo download Go language binary archive file, use the following command –$ wget https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gzThe sample output should be like this –--2016-12-29 10:49:44-- https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.197.48, 2404:6800:4007:807::2010 Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.197.48|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 81618401 (78M) [application/x-gzip] Saving to: ‘go1.7.1.linux-amd64.tar.gz’ go1.7.1.linux-amd64 100%[===================>] 77.84M 5.98MB/s in 16s ... Read More

Difference between Go and C++.

Mahesh Parahar
Updated on 28-Nov-2019 10:46:55

175 Views

GoGo is a procedural programming language. Programs are assembled using packages. It supports environment adopting patterns similar to dynamic languages.C++C++ is an object oriented programming language. C++ is quiet fast, reliable and secure. It is most widely used language as well.Following are the important differences between Go and C++.Sr. No.KeyGoC++1TypeGo is a procedural programming language and supports patterns similar to dynamic languages.C++ is an object oriented programming language.2Supports for ClassGo has no support for class with constructors.C++ has support for class with constructors.3Garbage CollectionGo has automatic garbage collection.C++ has not provided automatic garbage collection.4InheritanceGo has no support for inheritance.C++ supports ... Read More

Difference between Go and Java.

Mahesh Parahar
Updated on 28-Nov-2019 10:45:07

278 Views

GoGo is a procedural programming language. Programs are assembled using packages. It supports environment adopting patterns similar to dynamic languages.JavaJava is an object oriented programming language. Java is quiet fast, reliable and secure. It is most widely used language as well.Following are the important differences between Go and Java.Sr. No.KeyGoJava1TypeGo is a procedural programming language and supports patterns similar to dynamic languages.Java is an object oriented programming language.2Supports for ClassGo has no support for class with constructors.Java has support for class with constructors.3Exception HandlingGo has error handling instead of exception handling.Java has exception handling.4InheritanceGo has no support for inheritance.Java supports ... Read More

Advertisements