Found 33676 Articles for Programming

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

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

404 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

761 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

Golang Program to convert string variables to double

Akhil Sharma
Updated on 14-Nov-2022 12:13:24

2K+ Views

In this tutorial, we will learn how to convert string variables to double in Go programming language. String is a data type which is used to store characters or alphabets. Strings have a size of 1 byte or 8 bits. Whereas double is a data type which is used to store double precision floating point numbers. The size of double is 64 bits or 8 bytes. Program to Convert String type Variable to Double Using ParseFloat() Method Syntax func ParseFloat (s string, bitsize int) (float 64, error) ParseFloat() function is used to convert strings to float type values. This ... Read More

Golang Program to convert string type variables into int

Akhil Sharma
Updated on 14-Nov-2022 12:09:10

11K+ Views

In this tutorial, we will learn how to convert string type variables into int in Go programming language. For this task various types of string conversions are needed, to perform the conversions “strconv” package is imported in the go language program, Strings can be transformed into integer values using the ParseInt function. It decodes a string in the specified base (0, 2 to 36) and bit size (0, 64), and then it returns the equivalent result. Convert String Type Variable Into Int Syntax func ParseInt(s string, radix/base int, bitSize int) (i int64, err error) ParseInt() function is used to ... Read More

Golang Program to convert string type variables into Boolean

Akhil Sharma
Updated on 14-Nov-2022 12:04:37

5K+ Views

In this tutorial, we will learn how to f convert string type variables into Boolean in Go programming language. Boolean Vs String Boolean is a data type having 1-byte size. It can store any one of the three values mainly True, False or none. It acts like a flag to show whether a condition is correct or not. String data type is used to store a sequence of characters. it can be in the form of literals or alphabets. The size of string variable is 1 byte or 8 bits. For this task various types of string conversions are needed, ... Read More

Golang Program to convert Decimal to Octal

Akhil Sharma
Updated on 14-Nov-2022 11:53:21

806 Views

In this article you will know how to convert the decimal number to octal in Go language. For this we are going to use the FormatInt() function of strconv package. When we say convert the decimal number to octal, it means to convert the number with the base value 10 to the base value 8. The base value means the number of digits required to represent the numeric value. Example 1: Go Language Program to convert Decimal Number to Octal using Library Function Syntax func FormatInt(input int64, base int) string for [condition | ( init; condition; increment) | Range] ... Read More

Golang Program to convert Decimal to Hexadecimal

Akhil Sharma
Updated on 14-Nov-2022 11:46:41

3K+ Views

In this article you will learn the go language code to convert decimal number to Hexadecimal. Decimal Number Vs Hexadecimal Numbers Decimal numbers are the numbers which have base 10, which means each digit of a number can have an integer value ranging from 0 to 9 (10 possibilities) depending on its position. For example, 23 is a decimal number. Any number contains 16 digits in it, it is based on base 16, which means hexadecimal numbers contains decimal number from 0 to 9 and extra 6 Alphabets. A−F. In go language all the hexadecimal numbers start with 0x or ... Read More

Golang Program to convert Boolean to String

Akhil Sharma
Updated on 14-Nov-2022 11:36:09

4K+ Views

In this tutorial, we will learn how to convert Boolean to a string in Go programming language. Boolean Vs String Boolean is a data type having 1 byte size. It can store any one of the three values mainly True, False or none. It act like a flag to show whether a condition is correct or not. String data type is used to store a sequence of characters. it can be in the form of literals or alphabets. The size of string variable is 1 byte or 8 bits. Example 1: Convert Boolean type to String USING strconv.FormatBool() Method Syntax ... Read More

Golang Program to check the given number is an odd number using library function

Akhil Sharma
Updated on 14-Nov-2022 11:26:11

626 Views

In this article we will discuss about how to check if a given number is odd using library function Go language. ODD NUMBERS − In mathematics any number is called odd if it gives “1” as remainder when divided by “2”. For example 1, 3, 5, 7 …. Even Numbers − unlike odd numbers even numbers get completely divided by “2” and do not produce any remainder. For example − 2, 4, 6, 8 … Syntax func Mod(number1, number2 float64) float64 The mod() function is defined in the math package. This function returns the remainder by dividing the two numbers ... Read More

Golang Program to Check if An Array Contains a Given Value

Akhil Sharma
Updated on 14-Nov-2022 11:11:10

28K+ Views

In this tutorial we will learn how to check if a given value is present in a Go−lang array or not. We will use 2 methods for this. Method 1: Using a for loop directly in the main function We will use a for loop to iterate over the elements of an array in Golang and check for the equality of values using the equality operator. If the values match then we can stop the iteration and say that the given value is present in the array. Method 2: Using the function Golang does not have any pre-defined library function ... Read More

Advertisements