Display Alphabets A to Z Using Loop in Swift

Ankita Saini
Updated on 05-Aug-2022 08:40:12

1K+ Views

This tutorial will discuss how to write a Swift program to display alphabets (A to Z) using loop. In Swift, we can display alphabets starting from A to Z in both lower and upper case with the help of for-loop. Here we use the following terms in the below codes − Scalar − It represents a single value. Unicode − It is a standard encoding for text. UnicodeScalar − It represents a single Unicode scalar value. Below is a demonstration of the same − Suppose we enter the following input − A to Z Following is the desired output ... Read More

Display All Prime Numbers from 1 to N in Swift

Ankita Saini
Updated on 05-Aug-2022 08:34:45

5K+ Views

This tutorial will discuss how to write a Swift program to display all prime numbers from 1 to N. Prime numbers are those numbers that are greater than 1 and has exactly two factors that is 1 and the number itself. For example, 2 is the prime number because it has only two factors that are 1 and 2. Below is a demonstration of the same − Suppose we enter the following input − Range - 1 to 20 Following is the desired output − Prime numbers between 1 to 20 are - 2, 3, 5, 7, 11, ... Read More

Check If Two of Three Boolean Variables Are True in Swift

Ankita Saini
Updated on 05-Aug-2022 08:28:16

562 Views

This tutorial will discuss how to write a Swift program to check if two of three boolean variables are true. Given three boolean values now we have to check if two of the boolean variables are true or not. Boolean variables are those variables that either contain true or false. We can also use this program to check, out of given three conditions two are true or not. Below is a demonstration of the same − Suppose we enter the following input − Value1 = true Value2 = true Value3 = false Following is the desired output − Two of ... Read More

Swift Program to Display Fibonacci Series

Ankita Saini
Updated on 05-Aug-2022 08:24:24

7K+ Views

Fibonacci sequence is a sequence of numbers in which every number is the sum of the preceding two numbers and the starting number of this sequence are 0 and 1. So the general Fibonacci series is − 0, 1, 1, 2, 3, 5, 8, 13, 21, ...... Formula Following is the formula of Fibonacci series − Fn = Fn-1 + Fn-2 Below is a demonstration of the same − Suppose we enter the following input − Number = 5 Following is the desired output − Fibonacci Series is- 0, 1, 1, 2, 3 We can find the ... Read More

Count Number of Digits in an Integer Using Swift

Ankita Saini
Updated on 05-Aug-2022 08:08:16

3K+ Views

This tutorial will discuss how to write a Swift program to count the number of digits in an integer. Below is a demonstration of the same − Suppose we enter the following input − Number = 3454634 Following is the desired output − Total count is 7 We can count the number of digits using the following methods − Iterative method Recursion method Iterative Method We can calculate the total digits present in the given integer with the help of loops like if, while loop, etc. It is the easiest and cheapest method. Algorithm The algorithm ... Read More

Perform NCR Combinations in Swift

Ankita Saini
Updated on 05-Aug-2022 07:50:52

427 Views

This tutorial will discuss how to write a Swift program to perform nCr(r-combination). nCr refers to r- combination. It is used to calculate the possible arrangements where the order of the selection does not matter. Or we can say that nCr is used to select r items from the set of n items where the order of the items does not consider. Formula Following is the formula of nCr nCr = (n!)/(r! * (n - r)!) Below is a demonstration of the same − Suppose we enter the following input. N = 5 R = 3 Following is the ... Read More

Find the Largest Among Three Numbers in Swift

Ankita Saini
Updated on 05-Aug-2022 07:47:08

2K+ Views

This tutorial will discuss how to write a Swift program to find the largest among three numbers. Given three numbers now we have to find the largest among the given three numbers. So we will compare all three numbers with each other to find the largest number. Below is a demonstration of the same − Suppose we enter the following input − 39, 87, 12 Following is the desired output − Largest number is 87 Finding largest number using max() function Swift provides an in-built method named as max() function. This function returns the maximum number ... Read More

Swift Program to Find Factorial of a Number

Ankita Saini
Updated on 05-Aug-2022 07:38:43

5K+ Views

This tutorial will discuss how to write a Swift program to find factorial of a number. A Factorial of a non-negative number is calculated by multiplying the number with every whole number till 1 for example, 6! = 6 x 5 x 4 x 3 x 2 x 1 = 720 which means the factorial of 6 is 720. The general form of factorial is − M! = m x (m - 1) x (m - 2) x (m - 3) …. X 1 Formula Following is the formula of factorial − M! = M * (M - 1)! ... Read More

Uncurry a Function Up to Depth N in JavaScript

Imran Alam
Updated on 04-Aug-2022 11:50:37

256 Views

In JavaScript, a function is considered "curried" if it takes one or more arguments and returns a new function that expects the remaining arguments. Currying is a powerful technique that can be used to create new functions from existing ones, or to "uncurry" a function up to depth n. Why do we uncurry a function? There are several reasons why you might want to uncurry a function. For example, you may want to − Use a curried function in a context where a non-curried function is expected Convert a curried function to a non-curried form to make it easier ... Read More

Clone a Given Regular Expression in JavaScript

Imran Alam
Updated on 04-Aug-2022 11:49:04

370 Views

JavaScript's regular expression support is widely considered to be among the best in the world, but there's one area where it's lacking: there's no built-in way to clone a regular expression. This can be a problem when you need to create a new regular expression that is similar to an existing one but with a few small changes. The problem is that regular expressions are objects, and as such, they cannot be copied by simply assigning one to another. Consider the following code − var regex1 = /foo/; var regex2 = regex1; regex2 === regex1; // true In this ... Read More

Advertisements