{

Learn free golang-examples tutorials


2 ways to find swap two numbers/variables in Golang Example

December 1, 2022 ·  2 min read

In this article, you are about to learn two ways to swap two numbers or variables in Go language. The first method is to swap variables in a temporary variable, while the second alternative is not to use a temporary variable. How to Swap two numbers using a temporary variable? Two variables number1 and number2 are declared and assigned with 12 and 30 values respectively. Here is a sequence of steps for swapping numbers...


Golang Example - Calculate Sum of digits of an integer number

December 1, 2022 ·  3 min read

In this post, You will learn different ways to the addition of digits of a number in the Go language Using Iterative Function Using Recursive Function The Sum of digits of a number is to retrieve each digit of a number and add these numbers to the result. For example, if the given number is 154, The sum of digits of a number is 1+5+4=10....


Golang Example - Convert(Cast) String to/from Float

December 1, 2022 ·  3 min read

Contents Golang strconv package How to Convert String to float in Golang? Convert float number to String example fmt Sprintf function example strconv FormatFloat function example This post covers converting (cast) String type to float type or float type to String with an example. Golang strconv package The string is a group of characters referenced by a variable....


Golang Example - Find Factorial of a Number

December 1, 2022 ·  3 min read

Contents Example program to find factorial of a number using Iteration Function Example Program 2 - Recursive function Calculate Factorial of a number This blog post covers two programs to calculate the factorial of a number. Using the Recursion function Using Iterative Function Factorial of a number n is called n! which is equal to the product of all integers less than or equal to number n....


Golang example - Program to calculate Sum of natural numbers

December 1, 2022 ·  3 min read

This post cover three programs to find the sum of natural numbers Sum of first n natural numbers entered by the user Sum of first n natural numbers using for loop Sum of first n natural numbers Recursive function Natural numbers are positive integers or whole numbers which start from 0,1, 2 …. n. These are also called non-positive numbers. This post is about calculating the sum of natural numbers from 1 to n where n is read from the console by the user....


Golang Example - Program to Check ASCII Value of a character

December 1, 2022 ·  2 min read

In this example, you will learn below two programs in go language. How to display ASCII value of a character in Go language. Convert/cast Character to/from ASCII in golang ASCII is a code that contains 128 characters with integer values from 0 to 127. It can be stored in 8-bit types i.e byte In Go languages, There is no character type, but it can be represented in rune data type....


Golang Example - Reverse of a number or integer

December 1, 2022 ·  3 min read

In this program, You will see three programs. The first is to reverse a number or integer, the second program is the reverse number entered by the user, third is the reverse number using a recursive function in Go Language. To understand the below programs, You have the understanding of the following features in Go Language. Golang For Loop control structure Golang For Loop Range form Golang read input from user Array/Slice Tutorials Following is a sequence of steps....


Golang Example - strconv FormatInt Function Guide

December 1, 2022 ·  3 min read

Learn strconv FormatInt Function with examples in the Go Language. golang strconv FormatInt function strconv is a standard package in go language that provides various function implementations for converting a string to types into an int, float, boolean, etc. FormatInt is one of the important functions that is used to convert the Integer type to the String type. You can check official documentation is here Here is the syntax of this function...


Golang Example - strconv ParseFloat function guide

December 1, 2022 ·  3 min read

This blog post covers package strconv ParseFloat Function with examples in the Go Language. golang strconv ParseFloat function strconv is a standard inbuilt package in go language that provides various function implementations for converting a string to types into an int, float, boolean etc.. String to float is a common task of a programmer during development ParseFloat is an inbuilt function, converts a String value to a floating number...


Golang Example - strconv ParseInt Function explained

December 1, 2022 ·  3 min read

In this blog post, We are going to learn strconv ParseInt Function with examples in the Go Language. strconv ParseInt Function strconv package provides functions for converting String to or from different data types. PaseInt() is one of the functions used to convert String to Integer types and used for Number conversions. You can get official documentation from here Syntax Here is a signature of ParseInt example func ParseInt(s string, radix/base int, bitSize int) (i int64, err error) Arguments List -...


Golang Example - to check a number is a prime number or not

December 1, 2022 ·  3 min read

This post covers the three programs to check Prime numbers, One is prime number check for a fixed number, Second is to check prime number read input from user console, Third to check prime number check for bigint types. The prime number in mathematics is whole or positive greater than 1 which divides itself and one For example, the number can be divided with the remainder being zero. number 19 can be divided by 19 or 1 only....


Golang example How to calculate future compound interest

December 1, 2022 ·  2 min read

It is a short tutorial about how to calculate compound interest in the go language. Golang Compound Interest example program Compound interest is used in the calculating value of an amount in investment and finance domains. Compound interest is an interest applied to the principal, the period for the period. In mathematical terms, Compound interest has a formula as seen below. Future Compound Interest Amount = principal × ((interest rate/100)+1) power of number Interest Amount = Future Compound Interest Amount - Amount principal: principal amount Interest rate: It is a percentage value (%) the number is years in a period Let’s write a program to calculate compound interest in the go language In a program code,...


Golang Example programs with code

December 1, 2022 ·  2 min read

Go is a Static typed popular programming language. To learn a new programming language, We must write a practical example by making use of features. It is an index page for all golang features like control statements -loops, if-else, data types, data structures, classes, Conversions of one datatype to others, and objects. All the programs and examples are compiled and tested and given output. if you are new to go language, want to learn golang before working on this program, then have a look Golang Tutorials....


Golang Example to check Character is alphabetic or not

December 1, 2022 ·  2 min read

Learn programs on how to check whether the character is alphabetic or not in the go language. These do use an if-else statement and a switch case statement. Alphabetic characters are characters English letters in lower and upper case. Special characters are not allowed. Characters in go language represent the rune data type that contains the ASCII code value from 0 to 127. Please have a look at the below golang features to have an understanding of this program better....


Golang Example to check Largest, Smallest of three numbers

December 1, 2022 ·  3 min read

This post covers two programs, the First program is to check the largest of three numbers, and the second program is to check the smallest of three numbers. To understand these programs, You should have understood the following features if else statements Read input from user Example Program to check the largest/biggest of three numbers using an if-else statement In the below program, Read the three input numbers from the user using the Scanln function and store them in number1,numer2, and number3 variables...


golang example to check number/integer even or odd

December 1, 2022 ·  3 min read

Contents Golang Example program to check number is even or odd? Golang Program Example to check array or slices of Number are even or odd? Conclusion In this blog post, we will learn about two programs in golang. The first program is how to check input number is even or odd. the second program is how to check a given array or slice of numbers for even or odd numbers....


Golang Example to find larger/Maximum number of array or slice

December 1, 2022 ·  2 min read

In this blog post, We are going to learn to Find larger/maximum number of arrays or slice, reading input from an user array or slice holds the collection of elements. The array is fixed in size, Slice is dynamic. Golang program is to find the maximum or largest element in an array or slice. The logic of the below program, Initially, Array first element will be assumed as the largest element, compared with other elements, if elements are larger than other elements, It becomes a new larger element, The process continues execution until all elements are finished...


Golang Example to find quotient and remainder of a integers

December 1, 2022 ·  2 min read

In this example program, We will find quotient and remainder from the given numerator(dividend) and denominator (divisor) using modulus and division operators in Golang. Usually, The quotient is a result of the division operator in mathematics. In golang, division operator / is used and applied to integers. the remainder is a result of the modulus operator in mathematics. % symbol is defined in Golang. Find Quotient and Remainder for a given number in the golang program?...


Golang Example- 3 ways to check Length of a String output

December 1, 2022 ·  2 min read

In this blog post, You will learn three programs. The first program is the Length or count of characters/bytes of a String The second program is Length of runes in a String Third Program is to find the length of string using a pointer String is a sequence of characters that contains one or more words. In Golang, String is read-only of arbitrary bytes. Its length is the number of characters in a string....


Golang Example- How to print lowercase and upper case of a to z

December 1, 2022 ·  2 min read

This post covers two programs. the First program print lowercase a to z using for loop the Second program display uppercase A to Z using for loop. To understand this example, You should have the following features in the Go language. Golang For Loop control structure Golang For Loop Range form Golang Rune Datatype Beginner Guide Like other programming languages, there is no specific data type for Character representation....


Golang example-Calculate average Array/slice numbers

December 1, 2022 ·  2 min read

In this blog post, You will learn two programs for finding the average of array/slice numbers. First program to find the average of a fixed array of numbers The second program to read the input of values from a user via the command line calculates the average. Following are golang features are required to under this programs. Slice Guide For Loop Basics For Loop in range form How to check the average of an array of numbers in Golang Following is a sequence of steps....


Golang Example-Program arithmetic Calculator using switch case

December 1, 2022 ·  2 min read

This blog post covers an example for Arithmetic Simple Calculator using Switch case in Golang. To understand this example, You should have the following features in the Go language Golang read input from user Golang Switch case Guide Golang Operators Guide with examples Example program - arithmetic Calculator using switch case The below example is to write a Simple Calculator which supports arithmetic Operators such as Add, Subtract, Multiply, Modulus, Division operations....


GoLang Examples - Convert String to Int types with examples

December 1, 2022 ·  5 min read

This article talks about three ways to convert String to Integer in Go Language. Golang String int datatypes String and Int are different data types and hold different values. When we want to perform mathematical calculations on strings that contain numbers, we must convert string to int. if a user enters a numeric value in the text box of a web application form, this will be received as input as a string....


Golang examples to add/sum of two numbers or integers

December 1, 2022 ·  2 min read

In this program, we have two programs to add two numbers. In the First program, We will store the numbers and the addition of two numbers. The second program, take the two numbers from the user console and return the sum of two numbers. Example: Sum of two numbers In this program, variables are declared and initialized with inline assignment statements. This is one way of declaring multiple variables of the same type in golang....


Golang How to calculate simple interest in Golang

December 1, 2022 ·  2 min read

It is a short tutorial about how to calculate simple interest using golang what is Simple Interest with formula Simple interest is an interest applied to the principal amount applies to the rate of interest in a period for some time. Normally, To calculate simple interest in mathematical terms, We have used the formula. Simple Interest=P x N x R/100 P is the principal amount N is the Number of months R is the interest rate In a program code,...


Golang Map Example - Frequently Used programs

December 1, 2022 ·  7 min read

This post covers Golang Map types tutorials with examples In my previous post, Learned Golang Map Tutorials. Let’s see Map type examples in Go Language. How to Sort a Map by key or values in Golang? The map is an ordered data structure with key-value pairs in Golang. We have to write a custom code to sort maps, For example, we have a map of string key and int values....


Golang Program show value by reading user input from console

December 1, 2022 ·  3 min read

In this blog post, input data can be read from the console in many ways in the Go language. read input values using the scan function read multiple input values from the console read user input line by line using stdin stream Example to read user input using the scan function In this section, you learned how to read user input using the scan function. here is an example....


Golang Program to generate GUID or UUID with example

December 1, 2022 ·  2 min read

In this tutorial, Learned about how to generate GUID in golang with go.uuid and google.uuid packages. a unique identifier is a unique string to represent information in software applications. Two types of unique identifiers are used in applications. UUID - universally unique identifier, GUID - globally unique identifier These are used in the database for columns to act as the primary key in MongoDB or SQL database....


Golang Recursion - Recursive function with examples

December 1, 2022 ·  4 min read

In this blog post, we are going to learn Recursive functions in golang with examples. Contents what is the golang recursive function Recursion Syntax in Golang Golang Recursion function Example: Infinite times Golang Recursion function Example: finite times How to generate Factorial Number using Recursion function Example? Recursion example for calculating Fibonacci series Recursive anonymous function Conclusion what is the golang recursive function Recursion is a general programming code process in which the method or function calls itself continuously....


How to Calculate power or exponents of a Number in Golang Example

December 1, 2022 ·  3 min read

In this post, You will learn Three programs to calculate a power of a number. First, the program is to calculate the power of a number Second program to find the exponent of a number using the Math pow function The third program is to find the power of a number using a recursive function The power of m with exponent n also called m power n, is a product of the number n with m times....


How to check duplicates characters from a string in Golang

December 1, 2022 ·  2 min read

< image src=“golang/golang-example.png” alt=“Golang Program to check Duplicate characters” title=“Golang Example String contains Duplicate characters”>}} In this blog post, We are going to learn ways to check duplicate characters from a string. String is a group of any characters which are called a group of runes datatypes in Golang. It contains any characters, but sometimes duplicate characters also. We are going to learn the below things with duplicate characters in a string....


How to Check if a number is positive or negative in Golang

December 1, 2022 ·  2 min read

In this example, you will learn programs to check number is positive or negative, First using the [if else](/2018/11/learn-golang-tutorials-if-else.html) statement. The second is using the standard library Math Signbit function. Positive numbers are the whole number that is greater than zero ie 1,2,3… Negative numbers are numbers that are lesser than zero, -1,-2 Each positive number has a corresponding negative number To understand the below programs, You have the understanding the following features in Go Language....


How to check Leap year or not in Golang with example

December 1, 2022 ·  2 min read

In this blog post, We will write a program to check whether a given year is a leap year or not. How do you check if the year is a leap year or not? if the year is divisible by 4, check step 2, else go to step 5 if the year is divisible by 100, check step 3 else go to step 4 if the year is divisible by 400, check step 4, else go to step 5 Then the year is leap year which has 366 days This is not leap year which has 365 days Finally, if the year meets all the above conditions, Then it is a Leap year....


How to check string contains alphabetic char or not in Golang

December 1, 2022 ·  3 min read

< image src=“golang/golang-example.png” alt=“Golang Program to check string contains alphabetic char examples” title=“Golang Example String alphabet check”>}} This tutorial explains about how to Check Given string contains Alphabetic Characters or not Contents Golang String characters Examples Example 1: How to check if a string contains alphabetic characters? How to check if a string contains alphabetic characters using Regular Expression? How to Check if String contains Alphanumeric characters or special characters Conclusion Golang String characters Examples The string is a group of characters enclosed in double-quotes....


How to Check whether alphabet is Vowel or consonant in Golang

December 1, 2022 ·  3 min read

In this example, We will learn how to check whether the alphabet is vowel or consonant using [if else](/2018/11/learn-golang-tutorials-if-else.html) and [switch case](/https://www.2018/11/learn-golang-tutorials-switch-case.html) and Count of vowels in a String with an example. the vowel is called for a character if the Character contains any of the a, e, i, o, or u characters. consonant is a character that is not a vowels character. Please have a look at the below golang features before understanding these programs....


How to Convert Int to String type tutorials

December 1, 2022 ·  3 min read

Learn how String conversion from Int type in goes language with examples. int, String types in Golang In Any programming language, Anything users enter in text fields is always considered as String and saved to Database as Integer. you check my other post on Convert String to Int type. In some cases, we need to convert this Integer to String. For example, the integer contains numbers 167 and will convert this int to string as “167”....


How to count the number of digits in an integer| Go by Examples

December 1, 2022 ·  3 min read

This example covers two programs to count the number of digits in an integer. the first program uses the iterative function, The second program uses the Recursive function. Consequently, Both are used to implement digit count for a given number. you should be familiar with the following Go language features for this program. Golang For Loop control structure Golang For Loop Range form Golang read input from user Golang Recursion Function Guide The below code writes to read an integer value from a user keyboard and find the number of digits....


How to find Minimum of an array or slice in Golang Example

December 1, 2022 ·  3 min read

In these examples, You will learn how to find the minimum/smallest element of an array or slice from input from the user in Go Language. To understand the below programs, You have the understanding the following features in Go Language. Golang For Loop control structure Golang For Loop Range form Golang read input from user Array/Slice Tutorials The algorithm for this program is as follows....


How to get Docker Container in Golang | Container Id and IP Address

December 1, 2022 ·  2 min read

Contents Golang Get Container IP Address example Golang Get Container ID and Image details This tutorial explains how to get a container IP address in Golang. Containers are created using Docker tool. We can operate with docker commands to get contain container details. Sometimes, We need to write a golang code to access container details Golang Get Container IP Address example Inside a container, Write a golang program os package provides Hostname() method that returns a string and error....


How to get Local IP Address in Golang with example

December 1, 2022 ·  1 min read

This tutorial explains how to get a local IP address in Golang. Usually, When you retrieved the IP address using golang API’s, gives a loopback address 12.0.0.1 configured in the/etc/hosts file, and does not give a local public outbound IP address such as 132.121.xxx.xxx. How to get the Current Local outbound IP address in Golang Written golang function that returns net.IP object Created a connection by providing a GOOGle DNS server(8....


How to multiply two numbers in Golang | Go by Examples

December 1, 2022 ·  2 min read

In this blog post, Learn the below things in the go language. Multiply two integers Multiply two floating numbers Multiple integers and floating numbers Example program to Multiply two integers in Golang In this example. Declared two variables of type integer Assign them with values using the equal operator(=) Multiply two integers using multiply operator and the result is assigned to an integer variable. Finally, Print the result using %d in the Printf function....


How to trim/strip white spaces from a String in Golang Examples

December 1, 2022 ·  3 min read

In this blog post, You will learn three programs using the Strings package’s built-in functions. Contents How to trim whitespaces from a string in Golang Example program to strip leading and trailing spaces from a string Example program 3 to remove duplicate empty spaces from a string Conclusion Delete all whitespaces from a string Delete leading and trailing spaces of a string Remove duplicate spaces/tabs/newlines from a given string How to trim whitespaces from a string in Golang This program is to remove all white or empty spaces from a given string and returns the new string....


Multiple ways to Convert Hexadecimal to/from Integer Number in Golang

December 1, 2022 ·  4 min read

Contents Golang Hexadecimal Number System How to convert from Hexadecimal to Decimal Number in Golang? strconv ParseInt function example to cast Hexa to Decimal Integer strconv ParseUint function example to convert Hexadecimal to number Example Program to convert Decimal to HexaDecimal Number strconv FormatInt function example to convert Decimal to Hexa Number strconv FormatUint function example to convert Decimal to Hexadecimal Number Conclusion In this blog post, You will learn two programs in the Go language....


Multiple ways to Convert(cast) Octal to Decimal Number in Golang

December 1, 2022 ·  3 min read

Contents What is Octal Number? Example Program to convert Octal to Decimal Number strconv ParseInt function example to cast Octal to Decimal Custom Function without Predefined functions Example Program to convert Decimal to Octal Number strconv FormatInt function example to convert Decimal to Octal Custom function without inbuilt functionality In this blog post, You will learn two programs in the Go language....


Multiple ways to get Hostname and IP address in golang programs code

December 1, 2022 ·  3 min read

Golang net package The hostname is a label assigned to a machine that is connected to a network of machines. Golang standard package net provides functions related to TCP/IP, UDP, and DNS related networking related functionalities The following are various examples related to the hostname and Ip addresses in Go Language. How to Get Hostname of the System environment? It is always good to know the hostname of the environment where they go program is running....


Multiple ways to sum the elements of an array/slice in Golang example

December 1, 2022 ·  3 min read

This post covers some of the elements of an array/slice using the below approaches in the go language. sum array elements using for range form using variadic Functions Sum of elements entered by user input In golang, a group of elements is stored in an array or slice type. To understand the below programs, You have the understanding of the following features in Go Language. Golang functions guide Golang For Loop control structure Golang For Loop Range form Golang read input from user Array/Slice Tutorials Example program Sum of array elements using for loop range In this example, We will use for loop to iterate elements in an array or slice...


Multiple ways to to Convert(cast) Binary to/from Decimal in Goland With example code

December 1, 2022 ·  3 min read

Contents Golang parse Binary to Decimal Number How to convert Binary to a decimal using strconv ParseInt function? Manual Custom function to Cast Binary To decimal using for loop Example Program to convert Decimal to Binary Number strconv FormatInt function example to cast Decimal to Binary Cast Decimal to binary for loop without inbuilt function Conclusion In these posts, You will learn two programs in the Go language....


Print values of Array or slice in Golang example

December 1, 2022 ·  4 min read

Contents Example program: Print an Array or slice using For loop with range Example program2: Display Array or slice elements using Printf function Example Program 3 to Print Array or slices without Squrebrackets Example Program 4 Print address or pointer of array/slice Example Program 5 Print Array or slice bytes in binary bits form Conclusion In these examples, You will learn different ways to print/display array or slice elements to console in Go Language....


Subscribe
You'll get a notification every time a post gets published here.