# Learn free golang-examples tutorials

Golang How to calculate future compound interest in Golang

July 23, 2021 ·  2 min read

This is an short tutorial about how to calculate compound interest in go language what is Compound Interest with formula Compound interest is used in calculating value of an amount in investment and finance domains. Complex interest is a an interest applied to principal, period for period of time. In mathematical terms, Compound interest has a formula 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 an percentage value (%) number is an period in years Let’s write program to calculate compound interest in golanguage In a program code,...

Golang How to calculate simple interest in Golang

July 22, 2021 ·  2 min read

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

Golang Examples - remove/strp white spaces from a String

July 17, 2021 ·  3 min read

In this blog post, You will learn three programs using Strings package built-in functions Delete all whitespaces from a string Delete leading and trailing spaces of a string Remove duplicate spaces/tabs/newlines from a given string Example program to strip all whitespaces from a string This program is to remove the all white or empty spaces from a given string, return the new string. Standard inbuilt Strings package provides various utility string functions....

Golang examples to add/sum of two numbers or integers

July 17, 2021 ·  2 min read

In this program, we have two programs to add two numbers. 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 Example - Reverse of a number or integer

July 16, 2021 ·  3 min read

In this program, You will see a three program First is to reverse of a number or integer, the second program is the reverse number entered by user , thrid is reverse number using a recursive function in Go Language. To understanding the below programs, You have following features understanding 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...

Go By Examples - Map types Advanced Programs

July 16, 2021 ·  7 min read

This post covers Golang Map types tutorials with examples In my previous post, Covered Map guide in Golang Following are the Map type examples in Go Language How to Sort a Map by key or values? The map is ordered data structure of key-value pairs in Golang. To sort map, We have to write a custom code to handle this. For example, we have a map of string key and int values....

golang examples - Hostname and IP address programs code

July 16, 2021 ·  3 min read

Golang net package The hostname is a label assigned to a machine which is connected in 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 the go program is running....

GoLang Examples - Convert Int to String type tutorials

June 25, 2021 ·  3 min read

In this blog post, We are going to learn how String conversion from Int type in go language with examples. int, String types in Golang  In Any programming language, Anything user entered in text fields 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”....

Golang Example - Convert(cast) Binary to/from Decimal

June 20, 2021 ·  3 min read

In these posts, You will learn two programs in Go language The first program is to convert Binary Number to Decimal Number Second program to convert Decimal Number to Binary Number. A binary number is a number based on base 2. It contains either zero or one digits. Each digit is called a bit, Example binary numbers are 1011 Decimal Number are numbers which contain numbers based on base 10...

Golang Example - Calculate power or exponents of a Number

June 19, 2021 ·  3 min read

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

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

June 18, 2021 ·  2 min read

In this blog post, You will learn three programs First program is Length or count of Character/bytes of a String Second program is Length of runes in a String  Third Program is to find the length of string using pointer String is sequence of characters which contains one or more words. In Golang, String is read only of arbitary bytes.String length is number of characters in a string, For example, Given input string is “Cloudhadoop”, The length of the string is 11....

Golang Example - Calculate Sum of digits of a integer number

June 18, 2021 ·  3 min read

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

Golang Example - Find Factorial of a Number

June 18, 2021 ·  3 min read

This blog post covers two programs to calculate factorial of a number Using Recursion function Using Iterative Function Factorial of a number n is called n! which is equal to product of all integers less than or equal to number n. This will be always calculated for positive numbers and factorial of negative numbers not exists. Factorial of a number=0 is 1. For example Factorial of 5 is equal to 5!...

Golang Example-Print values of Array or slice

June 18, 2021 ·  4 min read

In thsi examples, You will learn different ways to print/display array or slice elements to console in Go Language. Following programs are covered Print Array using For Loop with range Display Slice using PrintF function format Array slice console print without Squarebrackets Print Address or pointer of array Print Slice of bytes in Binary Form To understand this example, You should have following features in Go language Golang For Loop control structure Golang For Loop Range form Array/Slice Tutorials  Example program: Print an Array or slice using For loop with range In the below program, Declared slice and array with initlized values using shorthand assignment operator....

Golang Example-Program arithmetic Calculator switch...case

June 17, 2021 ·  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 following features in Go language Golang read input from user Golang Switch case Guide Golang Operators Guide with examples Example program - Arthematic Calculator using switch case The below example is to write Simple Calculator which supports Arthematic Operators like Add, Subtract, Multiply, Modulus, Division First Read the input numbers from user keyboard console, stored in variable number1 and number2....

Golang Example-Display Lower/Upper Characters- rune

June 17, 2021 ·  2 min read

This post covers two programs, the First program is to print lowercase a to z using for loop, the Second program is to display uppercase A to Z using for loop. To understand this example, You should have following features in 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 to count number of digits in an integer

June 17, 2021 ·  3 min read

This example covers two programs to count the number of digits in an integer, the first program is using the iterative function, the Second program is using the Recursive function. To understand this example, You should have following features in Go language Golang For Loop control structure Golang For Loop Range form Golang read input from user Golang Recursion Function Guide Both programs read an integer value from a user keyboard, find the number of digits....

Golang Example-Program to find Minimum of array or slice

June 17, 2021 ·  2 min read

In this 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 understanding the below programs, You have following features understanding 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 At first, the starting element of an array assumed as the smallest element will compare with other elements if elements are smaller than other elements, It will be a new smaller element, This sequence of steps continues execution until all elements are traversed....

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

June 17, 2021 ·  2 min read

In this blog post, We are going to learn to Find larger/maximum number of array or slice, reading input fro an user array or slice holds the collection of elements. The array is fixed in size, Slice is dynamic in nature. 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 check Largest,Smallest of three numbers

June 17, 2021 ·  2 min read

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

Golang Example - to check number is prime number or not

June 16, 2021 ·  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 a whole or positive number greater than 1 which divides itself and one For example, Number can be divided with remainder is zero. number 19 can be only divided by 19 or 1 only....

Golang example to sum the elements of an array/slice

June 16, 2021 ·  3 min read

This post covers sum of elements of an array/slice using below approaches sum array elements using for range form using variadic Functions Sum of elements entered by user input To understanding the below programs, You have following features understanding 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 package main import ( "fmt" ) func sum(array []int) int { result := 0 for _, v := range array { result += v } return result } func main() { numb := []int{1, 2, 3, 4, 5} fmt....

Golang example - Program to calculate Sum of natural numbers

June 16, 2021 ·  3 min read

This post we will 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 starts from 0,1, 2 …. n. These also called nonpositive numbers. This post is about calculating the sum of natural numbers from 1 to n where n is read from console by the user....

Golang Program show value by reading user input from console

June 14, 2021 ·  3 min read

In this blog post, input data can be read from the console in the may ways in Go language read input values using the scan function read multiple input values from console read user input line by line using stdin stream Example to read user input using the scan function package main import ( "fmt" ) func main() { //reading an string var name string fmt.Print("What is your Name?...

Golang Program to generate GUID or UUID with example

June 14, 2021 ·  1 min read

unique identifier is an unique string to represent information in an software applications. Basically Two types of unique identifiers are used iin applications. UUID - universally unique identifier, GUID - globally unique identifier These are used in database for columns to act as primary key in mongodb or sql database. And also you can store cookie or session id in front end applications UUID or GUID is alias both refers same and contains 16 bytes or 128 bits in size separated in 5 groups by hyphens....

Golang Example - Program to check Leap year or not

June 14, 2021 ·  2 min read

In this blog post, We will write a program to check a given a year is a leap year or not Leap year is a year which meets following conditions 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 lear year which has 366 days This is not leap year which has 365 days Example program to check given year is a leap year or not The following features are used in go language...

Golang Example - Check alphabet is Vowel or consonant

June 14, 2021 ·  2 min read

In this example, We will learn below programs. how to check alphabet is vowel or consonant using if-else and switch case examples and Count of vowels in a String. the vowel is called for a character if Character contains any of a, e, i, o, u characters Please have a look of below golang features before understanding this programs Switch case Guide If else statement rune data type Example program to check alphabet is Vowel or consonant using if else statement package main import ( "fmt" ) func isVowel(character rune) { if character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u' { fmt....

GoLang Examples - Convert String to Int types with examples

June 14, 2021 ·  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 holds different values. When we want to perform mathematical calculations on strings that contain numbers, we must convert string to int. if a user enter numeric value in the text box of a web application form, this will be received as input as a string....

Golang Example to find quotient and remainder of a integers

June 13, 2021 ·  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 operator in Golang. 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 modulus operator in mathematics. % symbol is defined in Golang. Example: Find Quotient and Remainder The below example explains about golang arithmetic operators...

Golang Example to check Character is alphabetic or not

June 13, 2021 ·  2 min read

In this Example, You will learn programs how to check whether the character is alphabetic or not in go language using if else statement and switch case statement  Alphabetic characters are characters English letters in lower and upper case. Special characters are not allowed. Characters in go language are represented in rune data type which contains ASCII code value from 0 to 127. Please have a look of below golang features to have an understanding of this program better...

Golang Example - Program to Check ASCII Value of a character

June 13, 2021 ·  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 which contains 128 characters with integer values from 0 to 127. It can be stored in 8-bit types ie byte In Go languages, There is no character type, but it can be represented in rune data type....

Golang example - program to multiply two numbers

June 13, 2021 ·  2 min read

In this blog post, you are going to learn below things Multiply two integers  Multiply two floating numbers Multiply integer and floating numbers  Example1 program to Multiply two integers package main import ( "fmt" ) func main() { var number1, number2 int number1 = 5 number2 = 6 result := number1 * number2 fmt.Printf("Multiply result is %d\n", result) } Output is Multiply result is 30 Example2 program to Multiply two floating numbers package main import ( "fmt" ) func main() { var number1, number2 float64 number1 = 5....

Golang example-Calculate average Array/slice numbers

June 13, 2021 ·  2 min read

In this blog post, You will learn two programs for finding average of array/slice numbers. First program to find avrage of fixed array of numbers The second program to read the input of values from a user via 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 Example program to check average of an array of numbers First Array or integers is declared with inline assignment of the values...

golang example to check number/integer even or odd

June 13, 2021 ·  2 min read

In this blog post, we will learn two programs The first program is how to check input number is even or odd.the second program is how to check given array or slice of number for even or odd numbers. Even number is a number divisible to 2 is zero that means the number is even if operation modulus operator divisible by 2 is remainder=0 Example to check Number is even or odd In the below program....

Go Example-Program to check string contains alphabetic char

June 13, 2021 ·  2 min read

Golang String characters The string is a group of characters enclosed in double quotes. alphabetic characters - each character contains a letter from lowercase - a to z and uppercase - A to Z. alphanumeric characters - contain alphabetic and numeric characters. Special characters - a character are like %,# ..etc with excluding alphabetic and numeric characters. This post, You will learn the following things in GoLang Check String contains alphabetic Check String contains alphabetic using a regular expression Check String contains alphanumeric and special characters Example 1: How to check if a string contains alphabetic characters  String characters are iterated using for each loop....

Golang Example - Convert(cast) Octal to Decimal Number

June 12, 2021 ·  3 min read

In this blog post, You will learn two programs in Go language The first program is to convert Octal to Decimal Number The second program to convert Decimal to Octal Number. An Octal number is a number based on the base 8 number system. It contains digits from 0 to 7. In Golang, Octal numbers are always prefixed with zero Example octal numbers is 0879. Decimal Number are numbers which contain numbers based on base 10....

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

June 12, 2021 ·  3 min read

This post covers how to convert(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. A float is a numeric number that stores set of all IEEE-754 64-bit floating-point numbers. Both are of different types, Automatic conversions will not occur. The developer needs to write a code to handle this. Golang provides standard inbuilt package strconv to do string conversions to other types....

Golang Example - strconv FormatInt Function Guide

June 12, 2021 ·  3 min read

In this blog post, We are going to 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 important function that used to convert Integer type to String type. You can check official documentation is here Here is the syntax of this function...

Golang Example - strconv ParseInt Function explained

June 12, 2021 ·  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-Convert Hexadecimal to/from Integer Number

June 12, 2021 ·  4 min read

In this blog post, You will learn two programs in Go language, The first program is to convert Hexadecimal to Decimal Integer. The second program to convert Decimal to Hexadecimal Number. Golang Hexadecimal Number System Hexadecimal number is also called Hexa number which contains 16 digits i.e numbers start from 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. It is based on the Base 16 i.e Hexa number system. So HexaDecimal contains Decimal Numbers,0-9 (base 10) and Extra 6 alphabets - A to F...

Golang Recursion - Recursive function with examples

June 11, 2021 ·  4 min read

In this blog post, we are going to learn Recursive functions in golang with examples. Contents what is 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 golang recursive function Recursion is general programming code process in which method or function calls itself continuously....

Golang Example - strconv ParseFloat function guide

June 10, 2021 ·  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 You can check official documentation is here...

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

May 18, 2021 ·  2 min read

In this article, we’ll look at 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 number 2 are declared, and assigned them with 12 and 30 values respectively. Here is a sequence of steps for swapping numbers...

Golang Example programs with code

April 11, 2021 ·  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. This is an index page for all golang features like control statements -loops, if else, datatypes, 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 - Check if a number is positive or negative

April 10, 2021 ·  2 min read

In this Example, you will learn programs to check number is positive or negative, First using if else statement. Second is using standard library Math Signbit function. Positive number are whole number which are greater than zero ie 1,2,3… Negative numbers are number which are lesser than zero , -1,-2 Each positive number has a corresponding negative number To understanding the below programs, You have following features understanding in Go Language....

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