Found 517 Articles for Swift

Swift Program to Compute Quotient and Remainder

Ankita Saini
Updated on 18-Aug-2022 12:49:37

521 Views

This tutorial will discuss how to write a Swift program to compute quotient and remainder. In a division process, a number is divided by another number to get a resultant number. Or we can say that division is a process in which we divides larger number of group into small number of groups such that each group contain same number of elements. The four main terms of division are − Dividend − Dividend is a number which we divide. Divisor − Divisor is a number by which we divide Quotient − Quotient is the result obtained by the division. Remainder ... Read More

Swift Program to Print the ASCII values

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

2K+ Views

This tutorial will discuss how to write a Swift program to print the ASCII values. ASCII is known as American Standard Code for Information Interchange. In electronic communication, it is a character encoding standard to represent text in the computer and other devices. It generally has 128 standard ASCII codes including every upper case, lowercase alphabets, digits starting from 0-9 and symbols, etc., and assign each character a unique code. Below is a demonstration of the same − Suppose we enter the following input − Value = A Following is the desired output − ASCII value is 65 ... Read More

Swift Program to Get Input from the User

Ankita Saini
Updated on 05-Aug-2022 08:50:42

9K+ Views

Getting input from the user in Swift is very easy with the help of the readLine() function. This function returns a string of characters which is read from the standard input at the end of the current line. If the control is already reached the EOF when the readLine() function is called then this method will return nil. Syntax Following is the syntax of Swift readLine() function − readLine(strippingNewline: true) Or readLine() Reading integer Example The following program shows how to get input from the user. import Foundation import Glibc print("Please enter number 1") var num1 = ... Read More

Swift Program to Display Alphabets (A to Z) using loop

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

906 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

Swift Program to Display All Prime Numbers from 1 to N

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

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

Swift Program to Check if two of three boolean variables are true

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

385 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

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

Swift Program to Count Number of Digits in an Integer

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

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

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

Swift Program To Perform nCr (rcombinations)

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

223 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

Advertisements