Found 1082 Articles for Go Programming

How to find the Perimeter of a Rectangle in Golang?

Aman Sharma
Updated on 29-Aug-2022 07:46:18

177 Views

In this tutorial, we are going to see the Golang program to find the perimeter of a rectangle. Perimeter is the total length of the boundary of any closed figure Formula Perimeter of rectangle - 2 * ( L + B ) L - Length of a rectangle B - Breadth of a rectangle For example, the length of a rectangle is 100 cm and the breadth is 50 cm so the Perimeter of a rectangle is − Perimeter = 2 * (100 + 50) cm = 2 * (150) cm = 300 ... Read More

How to Calculate Compound Interest using Golang code?

Aman Sharma
Updated on 29-Aug-2022 07:37:29

324 Views

In this tutorial, we are going to see the program for calculating compound interest in Golang. It is a method of finding the accurate interest on loans in the banking and finance sector using factors like principal amount, rate per annum, and time. Due to more accuracy, the rates are higher than the simple interest. Formula compound_Interest = P * ( 1 + R / 100) ^ T P = Principal amount R = Rate per annum T = Time For example, suppose the principal amount is 1000, the rate of interest is 4 and the interval is 2 ... Read More

How to Calculate Simple Interest using Golang code?

Aman Sharma
Updated on 29-Aug-2022 07:16:52

318 Views

In this tutorial, we are going to see the program for calculating simple interest in Golang. It is a method of finding the interest on loans in the banking and finance sector using some factors like principal amount, rate per annum, and time. Formula simple_Interest = ( p * r * t) / 100P = Principal amountR = Rate per annumT = Time For example, suppose the principal amount is 1000, the rate of interest is 4 and the interval is 2 years then the simple interest is. Simple_interest = (1000 * 4 * 2) / 100 ... Read More

How to find the Factorial of a number in Golang?

Aman Sharma
Updated on 29-Aug-2022 06:55:21

2K+ Views

In this tutorial, we are going to write and explain the code to find the factorial of a number in Golang. The factorial is the multiplication of the number with all the numbers less than it. In this tutorial, we will see two ways to find the factorial in Golang. One is by creating a recursive function. Second, by using the for a loop. For example, the factorial of 5 is: 5! = 5 * 4 * 3 * 2 * 1 = 120 A recursive approach to finding the factorial of a number Algorithm STEP 1 − ... Read More

How to check whether the input number is a Neon Number in Golang?

Aman Sharma
Updated on 29-Aug-2022 06:49:28

212 Views

In this tutorial, we are going to write and explain the code to check whether the given number is a neon number or not. The Neon number is a number that is equal to the sum of all the digits of its square. For example, 9 is a neon number as shown below The square of 9 is: 9 * 9 = 81 The sum of each digit of the square i.e 81 is 9 and the number is also 9 so 9 is a Neon number. Algorithm STEP 1 − First we are declaring the numbers between ... Read More

How to Check Armstrong Number between Two Integers in Golang?

Aman Sharma
Updated on 29-Aug-2022 06:39:34

200 Views

In this tutorial, we are going to write and explain the code for finding the Armstrong number between two integers. The Armstrong number is a number whose sum of the cube of all the digits in the number is equal to the number itself. For example, 153 is a number as shown below 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 Algorithm STEP 1 − First we are declaring the numbers between which we have to find the Armstrong Numbers. STEP 2 − Now, we ... Read More

How to get Input from the User in Golang?

Aman Sharma
Updated on 26-Aug-2022 09:46:33

6K+ Views

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

How to Swap Two Numbers in Golang?

Aman Sharma
Updated on 26-Aug-2022 09:05:14

3K+ Views

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

How to Display Alphabets (A to Z) using a loop in Golang?

Aman Sharma
Updated on 26-Aug-2022 08:52:35

1K+ Views

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

How to Display all Prime Numbers from 1 to N in Golang?

Aman Sharma
Updated on 26-Aug-2022 09:51:55

1K+ Views

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

Advertisements