Found 33676 Articles for Programming

Swift Program to print the left diagonal matrix

Ankita Saini
Updated on 16-Feb-2023 16:44:06

491 Views

In this article, we will learn how to write a swift program to print the left diagonal matrix. A matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc. So here we print the left diagonal of square matrix. Square matrix is a matrix in which the number of rows and columns are same. For example 3x3, 5x5, 7x7, etc. Algorithm Step 1 − Create a function. Step 2 − Run for-in loop to iterate through each element of the matrix. Step 3 − Check ... Read More

Swift Program to Check whether a number is a Perfect Cube or not

Ankita Saini
Updated on 16-Feb-2023 16:43:03

962 Views

A number is a perfect cube if the result of the three time multiplication of a whole number is the number itself. For example: number 5 is a per Number = 125 125 = 5*5*5 Here 125 is a perfect cube. Number = 98 Here 98 is not a perfect cube. In this article, we will learn how to write a swift program to check whether a number is a perfect cube or not. Method 1: Using user defined function To check if the given number is a perfect cube or not, we create a function that check each number ... Read More

Swift Program to Check if the given number is Perfect number or not

Ankita Saini
Updated on 16-Feb-2023 16:41:41

535 Views

A perfect number is a positive number that is equal to the sum of its factors, excluding the number itself. For example − Number = 6 Proper divisors = 1, 2, 3 Hence, 6 is the perfect number because the sum of its divisors is 6(1+2+3) Number = 10 Proper divisors = 1, 2, 5 Hence, 10 is not a perfect number because the sum of its divisors is 8(1+2+5) In this article, we will learn how to write a swift program to check if the given number is a perfect number or not. Algorithm Step 1 − Create ... Read More

Swift Program to calculate the sum of rows of matrix elements

Ankita Saini
Updated on 16-Feb-2023 16:40:50

295 Views

A matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc.In this article, we will learn how to write a swift program to calculate the sum of rows of matrix elements. Here we are using the following methods to find the sum of the rows elements − Using nested for-in loop Using in-built function Method 1: Using nested for-in loop Here we use nested for-in loop to find the sum of rows of matrix elements. Algorithm Step 1 − Create a function. Step 2 ... Read More

Swift Program to Calculate the Sum of Matrix Elements

Ankita Saini
Updated on 16-Feb-2023 16:39:09

299 Views

A matrix is a rectangular array of numbers. Or we can say that a matrix is an arrangement of numbers in rows and columns. Matrix can be of various type like square matrix, horizontal matrix, vertical matrix etc. In this article, we will learn how to write a swift program to calculate the sum of matrix elements. So here, using the following methods we calculate the sum of matrix elements. Sum of square matrix elements Sum of any matrix elements For example, we have the following matrix − $\mathrm{Matrix\:=\:\begin{bmatrix}1 & 4 & 5 & 6ewline4 & 7 ... Read More

Swift Program to calculate the sum of columns of matrix elements

Ankita Saini
Updated on 16-Feb-2023 16:38:01

610 Views

A matrix is an arrangement of numbers in rows and columns. The matrix can be of various types like square, horizontal, vertical, etc. In this article, we will learn how to write a swift program to calculate the sum of columns of matrix elements. Here we are using the following methods to find the sum of the column’s elements − Using a nested for-in loop Using in-built function Method 1: Using nested for-in loop Here we use a nested for-in loop to find the sum of columns of matrix elements. Algorithm Step 1 − Create a function. Step ... Read More

Golang Program to check a string contains a specified substring or not

Akhil Sharma
Updated on 13-Feb-2023 17:05:39

6K+ Views

What is a string and a substring? A substring in Go is a portion of a larger string. It is specified by providing a start index and a length, and it contains the characters of the original string starting at the start index and going up to the specified length. The characters in a substring are still a part of the original string and share the same memory. In Go, a string is a sequence of characters. It is an immutable data type, meaning that once a string is created, it cannot be modified. Strings are enclosed in double quotes ... Read More

Golang Program to demonstrate the string concatenation

Akhil Sharma
Updated on 13-Feb-2023 16:59:10

240 Views

What is String Concatenation? In Go, string concatenation is the process of combining two or more strings into a single string. There are several ways to concatenate strings in Go. We shall discuss them in this article. Method 1: By Using User-Defined Function The function that we create will take two strings as arguments and will return the resultant string by combining both of them as the result. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Then create a function that will join the two strings together. The function accepts two ... Read More

Golang Program to demonstrate the escape sequence characters

Akhil Sharma
Updated on 13-Feb-2023 16:56:04

2K+ Views

In the go programming language, there are several types of special escape sequence characters. Usage of each one of them implements a different type of functionality. We shall discuss each one of them one by one in the upcoming examples. Example 1 In this example, we will write a go language program to demonstrate the backlash (//) character. It is used to display a slash in the output of the program. package main import "fmt" func main() { fmt.Println("Program to display a backslash using in the program") } Output Program to display a backslash using in the program\ ... Read More

Golang Program to demonstrate the example to write double quotes in a string

Akhil Sharma
Updated on 13-Feb-2023 16:49:40

2K+ Views

In Golang there are various techniques of printing double-quotes in the string. In this article, we are going to learn those techniques with various example. Syntax func Quote(s string) string Quote() function is present in strconv() package and is used to add a given string literal in double quotes. The function accepts the string variable that is to be quoted as an argument and returns the string after adding double quotes to it. func Sprintf(format string, a ...interface{}) string This function returns a formatted string. It takes a number of arguments in string format. The first argument should ... Read More

Advertisements