Found 33676 Articles for Programming

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

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

2K+ 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

2K+ 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

How to add two Complex numbers in Golang?

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

836 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

2K+ 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

1K+ 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

6K+ 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

13K+ 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

Built-in functions supported by dictionary view objects

Govind
Updated on 25-Aug-2022 11:38:58

514 Views

The dictionary view objects include dict.keys(), dict.values(), dict.items(). They are used to obtain the dynamic view of the dictionary elements in python. These objects reflect the changes made to the dictionary. To retrieve some data or perform various operations on these view objects, there are 5 build-in functions in python that are supported. They are as follows − len(obj) iter(obj) reversed(obj) sorted(obj) ist(obj) We will discuss about all the functions mentioned above in this article. The len(obj) method The len(obj) method takes a view object as a parameter and returns the number of items in the dictionary. Example ... Read More

Swift Program to find the tangent of given radian value

Ankita Saini
Updated on 26-Aug-2022 11:36:09

245 Views

This tutorial will discuss how to write a Swift program to find the tangent of given radian value. A tangent function is used to define the ratio of the length of the opposite side to the adjacent side in the right-angled triangle. It is also known as the tan function. The mathematical representation of the tangent() function is − tan() = opposite side/adjacent Side In Swift, we can calculate the tangent of the given radian value using the pre-defined tan() function. This function returns the tangent value of the specified number. Here, the specified number represent an angle. Syntax ... Read More

Swift Program to find the cosine of given radian value

Ankita Saini
Updated on 25-Aug-2022 09:02:20

511 Views

This tutorial will discuss how to write a Swift program to find the cosine of given radian value. A cosine function is used to define the ratio of the length of the adjacent side to the hypotenuse in the right-angled triangle. It is also known as the cos function. The mathematical representation of the cosine() function is − cos() = adjacent Side/ hypotenuse In Swift, we can calculate the cosine of the given radian value using the pre-defined cos() function. This function return the cosine value of the specified number between -1 to 1. Here, the specified number represent ... Read More

Advertisements