Found 1082 Articles for Go Programming

How to add two Complex numbers in Golang?

Aman Sharma
Updated on 26-Aug-2022 08:27:53

492 Views

In this tutorial, we will learn how to declare and add complex numbers in Golang. Complex numbers are something that has an imaginary and real part which will make them different from other types of numbers. Golang supports declaring a variable of complex number type. Complex Number = Real Number + Imaginary Number Different ways to declare and initialize complex numbers and add them later in Golang. Initializing using complex number init syntax Syntax var variableName complex64 var variableName complex128 variableName = (realValue) ... Read More

How to add Two Binary Strings in Golang?

Aman Sharma
Updated on 26-Aug-2022 08:25:40

940 Views

This tutorial will show how we can add two binary strings in Golang. Also, we will cover and understand all the cases while adding two strings using examples. Example Suppose we want to add these two binary strings “111” and “1011” whose numeric values are 7 and 11 whose addition is 18 with binary representation “10010”. Now we will do the addition of these strings step by step below.variables with the respective values you want to multiply. As you can see the length of string “111” is less than “1011” so we have to make them equal for which ... Read More

How to Multiply Two Floating-Point Numbers in Golang?

Aman Sharma
Updated on 26-Aug-2022 08:04:03

741 Views

This tutorial will show how to multiply two float numbers within a function or by creating a separate function and calling it in the current function. Multiplying two float numbers within the function Algorithm STEP 1 − Defining the floating variables that we want to multiply and the floating variable in which we will add the result. STEP 2 − Initialize the variables with the respective values you want to multiply. STEP 3 − Multiply two numbers and store them in the third variable. STEP 4 − Print the result after multiplying two numbers. Example package main ... Read More

How to Add Two Numbers in Golang?

Aman Sharma
Updated on 26-Aug-2022 08:00:01

4K+ Views

In this tutorial, we will discuss adding two numbers in Golang. We will cover two approaches first adding two numbers within the function and second creating a different function. Adding two numbers within the function Algorithm STEP 1 − Defining the variables that we want to add. STEP 2 − Initializing the variables. STEP 3 − Add two numbers and store them in the third variable. STEP 4 − Print the result after adding two numbers. Example 1 In this example, we will add two integers within the function. package main // fmt package provides the function ... Read More

How to print a string in Golang?

Aman Sharma
Updated on 26-Aug-2022 07:46:44

9K+ Views

In this tutorial, we will learn how to print a string in the Golang programming language. To print a string in Golang we have to use the package fmt which contains the input/output functions. The correct specifier tells the data type of variable we are printing. The specifiers we can use to print the strings are: %s − By using this we can print the uninterpreted strings or slice. %q − By using this we can print the string with double quotes. %x − By using this we can print the lower case character string with base 16. %X − By using this ... Read More

How to Print an Integer in Golang?

Aman Sharma
Updated on 26-Aug-2022 07:36:53

10K+ Views

In this tutorial, we will learn how to print an integer in the Golang Programming language. The fmt package is used to perform the input/output operations which are comparable to the input/output functions in C i.e scanf and printf. Also, format specifiers are referred from C but in Golang they are simple. We will discuss what specifiers we have for integers. Specifiers are something which will tell us the what data type we are printing. %b − for base 2 %o − for bae 8 %d − for base 10 Functions in fmt package:− fmt.Printf() − It ... Read More

What are the differences between C++ and Go?

Bhanu Priya
Updated on 23-Mar-2022 10:40:52

266 Views

Let us understand the concepts of C++ and Go before learning the differences between them.GoIt is an open source programming language developed by Google employees, It is intended to be fast compiled, garbage collected, strongly typed, and with explicit support for concurrent programming.The original developers Rob Pike, Robert Griesemer and Ken Thompson started out in the year 2007. It was licensed under the BSD license. In the case of large systems it supports statically typing and scalability.FeaturesThe features of Go are as follows −Language DesignPowerful standard libraryPackage ManagementStatic TypingTesting SupportC-inspired syntaxCompiledSafe and open sourceAdvantagesThe advantages of Go are as follows ... Read More

How to convert a string into Title Case in Golang?

Syed Abeed
Updated on 10-Mar-2022 10:06:07

4K+ Views

Title() is a built-in function of strings package in Golang that is used to convert a string into Title Case. It converts the first character of each word in a given string into uppercase and returns the modified string.Syntaxfunc Title(s string) stringWhere s is the given string.Example 1Let us consider the following example −package main import (    "fmt"    "strings" ) func main() {    // Intializing the Strings    m := "title string function"    n := "Golang string package fUNCTION"    // Display the Strings    fmt.Println("String 1:", m)    fmt.Println("String 2:", n)    // ... Read More

strings.SplitAfter() Function in Golang

Syed Abeed
Updated on 10-Mar-2022 09:53:55

1K+ Views

strings.SplitAfter() is a built-in function in Golang that is used to break a string into a slice. SplitAfter is different from other Split functions. Here, we slice a given string into substrings after each instance of separators and it returns a slice of those substrings.Syntaxfunc SplitAfter(S String, sep string) []stringWhere s is the given string and sep is the separator string.Example 1Consider the following example −package main import (    "fmt"    "strings" ) func main() {    // Intializing the Strings    x := "Golang Program of SplitAfter Function"    y := "1.2.3.4.5.6.7.8"        // Display the ... Read More

Golang – strings.SplitN()

Syed Abeed
Updated on 10-Mar-2022 09:49:51

616 Views

strings.SplitN() is a built-in function in Golang that is used to split a given string into substrings by the given separator. It returns the slices of the substrings between those separators.Syntaxfunc SplitN(str, sep string, n int) []stringWhere, str is the given input string, sep is the separator string, andn defines the number of substrings that is to be returned.Example 1Consider the following example −package main import (    "fmt"    "strings" ) func main() {    // Intializing the Strings    p := "1, 2, 3, 4, 5, 6, 7"    q := "Welcome to Golang Programming Language"    r := ... Read More

Advertisements