Found 1082 Articles for Go Programming

Golang Program to Check if a String is Numeric

Akhil Sharma
Updated on 15-Nov-2022 13:00:36

8K+ Views

In this tutorial, we will learn how to check if a given string is numeric or not using Go programming language. We will be using the regexp package in Go to validate the numeric patterning of the string. Examples of numeric string − A string which has a numeric value in it T20CRICKET GOOD1 100PERCENT Syntax func MustCompile(str string) *Regexp //This function creates the regular expression func MatchString(pattern string, s string) (matched bool, err error) // This function returns a Boolean value that indicates whether a pattern is matched by the string Example 1: Golang Program Code ... Read More

Golang Program to Check For Armstrong Number

Akhil Sharma
Updated on 15-Nov-2022 12:21:48

650 Views

In this tutorial, we will learn how to check for Armstrong number in Go programming language. An Armstrong number or the narcissist number is a number whose sum of digits raised to the power three equals the number itself. Example1: $\mathrm{(1^3) \:+ \:(5^3) \:+ \:(3^3)\:= \:153}$ Example2: $\mathrm{(3^3) \:+ \:(7^3) \:+ \:(1^3)\:= \:371}$ In the below examples, we will read an integer number and then check the given number is an Armstrong number using Golang program Syntax Syntax of For loop Initialize for condition { } incrementor The initialization statement is optional and executes before for ... Read More

Golang Program to Calculate The Power using Recursion

Akhil Sharma
Updated on 15-Nov-2022 12:09:24

551 Views

In this tutorial, we will learn how to calculate the power using recursion technique in Go programming language. Power can be defined as a number being multiplied by itself a specific number of times. Exponent can be defined to the number of times a number is used in a multiplication. Powers and exponents are important tools to rewrite long multiplication problems in mathematics, especially in algebra. Example: 24 = 2 × 2 × 2 × 2 = 16, where 2 is the base and 4 is the exponent. A Recursion is where a function calls itself by direct or indirect ... Read More

Golang Program to Print Right Triangle Star Pattern

Akhil Sharma
Updated on 15-Nov-2022 12:05:22

688 Views

In this tutorial we will write a Go-lang code to print a right Triangle star pattern. We will depict how you can print the star pattern in go language. * * * * * * * * * * How to print a star pattern? A right triangle star pattern is shown above, and in that pattern, you can see that stars are increasing with the increase in the number of rows. The pattern goes like this 1 star in first row, 2 stars in second row, and goes on. For loop for [condition | ( init; condition; increment) ... Read More

Golang Program to Print Left Triangle Star Pattern

Akhil Sharma
Updated on 15-Nov-2022 12:01:12

361 Views

In this tutorial we will write a Go-lang code to print a Left Triangle star pattern. We will depict how you can print the star pattern in go language. * * * * * * * * * * How to print a star pattern? A left triangle star pattern is shown above, and in this pattern, you can see that stars are increasing with the increase in the number of rows. The pattern goes like this 1 star in first row, 2 stars in second row, and goes on. We will be ... Read More

Golang Program to Print Half Diamond Star Pattern

Akhil Sharma
Updated on 15-Nov-2022 11:32:13

275 Views

In this tutorial, we will learn how to print half diamond star pattern using Go programming language. Syntax for initialization; condition; update { statement(s) } To use a for loop in go lang we first need to initialize a variable then specify the condition of the loop i.e when should the loop end then we need to increment or decrement the variable followed by the lines of codes that should get executed. Example 1: Golang Program Code to print Half Diamond Star Pattern Using a Single Function Approach The goal is to divide the pattern into ... Read More

Golang Program to get the real part from a Complex number

Akhil Sharma
Updated on 15-Nov-2022 11:28:26

405 Views

In this article we will discuss about how to get real part from a complex number in Go language. A complex number in mathematics is a number that can be expressed in the form of a + ib where i is called iota. The value of iota is $\mathrm{\sqrt{-1}}$ and a and b are real numbers. The first part i.e ‘a’ is called real part of complex number and the part after iota i.e ’b’ is called imaginary part of complex number. Syntax func real(number complex128) float64 The real() function is used to get the get the real part ... Read More

Golang Program to get the magnitude of the given number

Akhil Sharma
Updated on 14-Nov-2022 12:51:31

475 Views

In this article we will discuss about how to get the magnitude of a number in Go language. Magnitude of a quantity is defined as its numeric value. Magnitude of a number is always positive. In this article we will discuss about different methods by which we can obtain the magnitude of any number. Syntax func Abs(number float64) float64 Abs() is a method defined in math library. This method accepts a 64 bit float number as an argument and return the absolute value of it excluding the sign. The source code to the above stated problem is compiled and ... Read More

Golang Program to Display Prime Numbers Between Two Intervals using library functions.

Akhil Sharma
Updated on 14-Nov-2022 12:44:35

300 Views

In this article we will discuss about how to display prime numbers between two intervals using functions in Go language. Syntax func Sieve(n int) []int func IsPrime(n int) bool If else conditionals in GO language: If condition { // code to be executed } else { // code to be executed } For loop as a while loop in GO language: for condition { // code to be executed // increment or decrement the count variable. } Sieve() function defined in primes package accepts ... Read More

Golang Program to create Complex numbers from given imaginary parts using In-build Library Function

Akhil Sharma
Updated on 14-Nov-2022 12:18:07

567 Views

In this tutorial we will learn how to create Complex numbers from given imaginary parts in Go programming language. A complex number is a basic data type of GoLang and is a combination of the real and imaginary part, where both parts of the complex number will be float type in golang. Complex Number = Real Number + Imaginary Number The function complex()in Go programming language is a built-in function that is used to construct a complex number from two floating-point values. The real and imaginary parts of the complex value must be of the same size and the return ... Read More

Advertisements