Programming Articles - Page 516 of 3363

Swift Program to Calculate Average Using Arrays

Ankita Saini
Updated on 29-Dec-2022 15:53:37

3K+ Views

In this article, we will learn how to write a swift program to calculate averages using an array. Average is defined as the ratio of the sum of the elements present in the given sequence to the total number of elements available in the given sequence. The general formula of average is − Average = (p1+p2+p3+..+pn)/n Here we use the following methods to calculate the average using array − Using pre−define functions Without using predefine functions Method 1: Using Pre-Define Functions To find the average of the given array, we use reduce() method to find the sum ... Read More

Golang Program to Find the Product of Two Numbers Using Recursion

Akhil Sharma
Updated on 29-Dec-2022 12:27:42

429 Views

The product of two numbers is the result you get when you multiply them together. So 15 is the product of 3 and 5 and 22 is the product of 2 and 11 and so on. A Recursion is where a function calls itself by direct or indirect means. Every recursive function has a base case or base condition which is the final executable statement in recursion and halts further calls. Example-1: Golang Program Code to Find The Product of Two Numbers Using Recursion by Using The Direct Recursion Method Syntax Syntax for direct recursion func recursion() { ... Read More

Golang Program to Display Factors of a Number

Akhil Sharma
Updated on 29-Dec-2022 12:25:10

972 Views

In this tutorial program, we will learn how to display the factors of a given number in the Go programming language. A factor of a number is defined as the algebraic expression that divides any given number evenly, with its remainder being zero. All composite numbers will have more than two factors, that include 1 and the number itself also. For example: by multiplying 3 and 7, we get 21. We say 3 and 7 are factors of 21. Below is a demonstration of the same − Input Suppose our input is = 15 Output The factors of 15 ... Read More

Golang Program to Convert String Value to Byte Value

Akhil Sharma
Updated on 07-Oct-2023 01:11:06

33K+ Views

In this tutorial, we will learn how to convert string values to byte values using golang programming language. String Value − A string value is just a sequence of characters, like "abc". A string value is always enclosed in quotes. All types of characters are allowed (even digits, as in "abc123"). Strings can contain any number of characters. Byte value − The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where ... Read More

Golang Program to Convert Char Type Variables to Int Using Inbuilt Functions

Akhil Sharma
Updated on 29-Dec-2022 12:18:04

5K+ Views

In this tutorial, we will learn how to convert character type to integer type variable using Golang programming language. In the Go programming language, there is no char data type. It uses bytes and rune and strings to represent character values. Example-1: Golang Program Code to Convert Char to Int Using Atoi() Function Syntax func Atoi(str string) (int, error) Here, str is the string. Atoi() function is equivalent to ParseInt(str string, base int, bitSize int) is used to convert string type into int type and to access Atoi() function you need to import strconv Package in your program. Algorithm ... Read More

Golang Program To Convert Array To Set

Akhil Sharma
Updated on 29-Dec-2022 12:15:18

4K+ Views

In this tutorial, we will learn how to convert an array to a set using the Golang programming language. A Set is a collection of items. You can iterate on these items / add new / remove items and clear the set and get the size and check if the set contains any value. An object in the set might only be stored once and cannot duplicate. Syntax var myset map[type]struct{} Key is a type of data you want to create. Struct{} is an empty struct that takes 0 bytes in size. Example 1: Go Code to Convert an ... Read More

Golang Program to Show Encapsulation in Class

Akhil Sharma
Updated on 29-Dec-2022 12:12:43

491 Views

In this article, we are going to learn about Encapsulation in class using Golang Program Encapsulation in go Language vs Other Object-Oriented Languages − The variables or data of a class in object-oriented languages are private to that class and can only be accessed through any member functions of the class in which they are specified. However, classes and objects are not supported by the Go language. So using packages to accomplish encapsulation in the Go programming language. Go offers exported and unexported identifiers, two separate forms of identifiers. Exporting variables, functions, methods, fields, and structures from the packages enables ... Read More

Golang Program To Convert Set Of String To Array Of String

Akhil Sharma
Updated on 28-Dec-2022 17:03:22

3K+ Views

In this tutorial, we will write a golang program to convert a set of strings to array of strings. In go a set is an abstract data type that can store specific values without repeating any of them and without any particular sequence. Convert Set Of String To Array Of Strings Using Internal Functions The program to convert a set of strings to array of strings using predefined functions in go programming language is given below. Syntax func make([]type, length, capacity) []type The make function is used to make a slice or map. It takes three arguments one is ... Read More

Golang Program to Convert List to Set

Akhil Sharma
Updated on 28-Dec-2022 16:42:50

1K+ Views

In this tutorial, we will write a golang program to convert a list to set. A linked list is a structure that is created dynamically it has two elements one to store the value and other to store the address of the next structure. A set is an abstract data type that can store specific values without repeating any of them and without any particular sequence. Convert a Linked List to a Set Now let us look at an example to convert the linked list to a set. Syntax func make([]type, length, capacity) []type The make function is used ... Read More

Golang Program to Convert List to Map

Akhil Sharma
Updated on 28-Dec-2022 16:40:16

1K+ Views

In this tutorial, we will write a golang program to convert a list to map. A linked list is a structure that is created dynamically it has two elements one to store the value and other to store the address of the next structure. A map store element in key:value pairs. A map is an unsorted, flexible collection that forbids duplications. Convert A List to Map In this article, we will discuss to convert a linked list to map. The following program illustrates this conversion process. Syntax func make([]type, length, capacity) []type The make function is used to make ... Read More

Advertisements