Check If Two of Three Boolean Variables Are True in Swift

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

515 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

Swift Program to Reverse a Number

Ankita Saini
Updated on 05-Aug-2022 07:53:46

3K+ Views

This tutorial will discuss how to write a Swift program to reverse a number. Reversing a number is a process in which the position of the digits of a number is interchanged to reverse their order. Below is a demonstration of the same − Suppose we enter the following input − Number = 098627 Following is the desired output − Reversed order = 726890 Algorithm Following is The algorithm to reverse the number − Step 1 − Start Step 2 − Create a variable named “number”. Now the value of the “number” variable is either user-defined or ... Read More

Perform NCR Combinations in Swift

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

371 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

Clone an Object Using Spread Operator in JavaScript

Manisha Patil
Updated on 04-Aug-2022 11:55:49

2K+ Views

The spread operator, which was first introduced in ES6, is used to unpack the elements of an iterable like an array. Cloning and merging the array is simple thanks to the spread operator. The spread operator could not be used with objects when it was first introduced in ES6. The spread operator was eventually extended to objects in ES2018. You'll learn how to use the JavaScript object spread (...) to clone an object or merge two objects into one in this article. In areas where 0+ arguments are expected, the spread operator allows an iterable to extend. This is most ... Read More

Uncurry a Function Up to Depth N in JavaScript

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

218 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

Check Whether a NaN is a NaN in JavaScript

Manisha Patil
Updated on 04-Aug-2022 11:50:13

401 Views

In this article let us understand how to check whether a NaN is a NaN or not in JavaScript. Literal constant that is not quoted Not-a-Number is represented by NaN, a special value. NaN is commonly used to signal an error condition for a function that should return a valid number since it always compares unequally to any number, including NaN. Differentiating between different undefined values in JavaScript can be tricky. When working with NaN values in Boolean operations, there are a handful of difficulties to be careful of. The numeric type in JavaScript permits you to describe numbers of ... Read More

Advertisements