In this tutorial, we will learn how to print the prime numbers from 1 to N where N the value of N will be as an input from the user. Just a short brief about Prime numbers is that the Prime numbers are something which can be only divisible by 1 or itself. In this tutorial, we are going to discuss two approaches one which will take O(N^2) of time and the other will take O(N*log(logN)). Method 1 Time Complexity: O(N^2) Space Complexity: O(1) Algorithm STEP 1 − Declaring the number N of type int32 STEP 2 − Take ... Read More
In this tutorial, we will see how to get the input from the user in Golang. Golang has a library that consists of an input/output function which helps in printing and taking the output. The function to take the input is Scanln(). Algorithm For Taking Integer Input with User STEP 1 − We are importing the fmt package that has the input/output functions. STEP 2 − We are declaring a variable after that we are printing the lines to ask the user to give the input STEP 3 − Then using fmt.Scanln() we are taking the input and storing ... Read More
In this tutorial, we will discuss swapping two numbers in Golang. We will cover two approaches: first swapping two numbers within the function and second creating a different function. Swapping two numbers within the function Algorithm STEP 1 − Defining the variables that we want to Swap. STEP 2 − Initializing the variables. STEP 3 − Swapping the two variables within the function. STEP 4 − Print the variables after swapping. Example package main // fmt package provides the function to print anything import "fmt" func main() { // define the variables we ... Read More
In this tutorial, we are going to print the alphabet from A to Z. The logic we are going to use to print the alphabet is ASCII values. Every symbol, alphabet, or number has a unique ASCII value using which we can print the Alphabets using a loop. The ASCII value of A is 65 and the ASCII value of Z is 90. A = 65B =66C = 67.....Z = 90 Algorithm STEP 1 − First we are declaring an integer with the ASCII number of A i.e 65. STEP 2 − Then we are running a ... Read More
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP