Found 517 Articles for Swift

Swift program to convert string type variable into boolean

Ankita Saini
Updated on 13-Dec-2022 14:41:36

929 Views

This tutorial will discuss how to write swift program to convert string type variable to boolean. Swift support various datatypes and string and bool are one of them. String is an ordered collection of characters. For example: “TutorialsPoint”, “Pinky”, etc. To create a string type variable we use String keyword. Whereas Boolean represent bool values. Bool has only two values either true or false. And to create boolean type variable we use Bool keyword. Swift does not provide any dedicated constructor (like String(), Int())to convert String into Bool. So we can convert boolean to string using any of the following ... Read More

Swift program to convert boolean variable into string

Ankita Saini
Updated on 13-Dec-2022 14:35:32

1K+ Views

This tutorial will discuss how to write swift program to convert boolean type variable to string. Swift support various datatypes and string and bool are one of them. String is an ordered collection of characters. For example: “TutorialsPoint”, “Pinky”, etc. To create a string type variable we use String keyword. Whereas Boolean represent bool values. Bool has only two values either true or false. And to create boolean type variable we use Bool keyword. To convert bool type variable into string we uses String() function. This function convert any data type into string. Syntax Following is the syntax − String(variableName) ... Read More

Swift program to print hollow rectangle star pattern

Ankita Saini
Updated on 13-Dec-2022 14:32:06

401 Views

This tutorial will discuss how to write swift program to print hollow rectangle star pattern. Star pattern is a sequence of “*” which is used to develop different patterns or shapes like pyramid, rectangle, cross, etc. These star patterns are generally used to understand or practice the program flow controls, also they are good for logical thinking. To create a hollow rectangle star pattern we can use any of the following methods − Using nested for loop Using stride Function Below is a demonstration of the same − Input Suppose our given input is − Length = 10 ... Read More

Swift program to print Hello World!

Ankita Saini
Updated on 13-Dec-2022 12:52:21

225 Views

This tutorial will discuss how to write swift program to print Hello World. Hello world programs are the most basic program of any programming language. It is used to learn how we can simply print “Hello world” on the screen using Swift language. Example Hello world program The following program shows how to print hello world. import Swift // Printing hello world print("Hello World") Output Hello World Here we simply print hello world on the output screen using print() function. The syntax of Swift is quit easy and time saver. Like other languages you did not required ... Read More

Swift program to convert the decimal number to binary using recursion

Ankita Saini
Updated on 13-Dec-2022 12:49:52

221 Views

This tutorial will discuss how to write Swift program to convert the decimal number to binary using recursion. Decimal numbers are those numbers whose base value is 10. Decimal numbers are also known as base-10 number system which contain 10 numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Here, the position of every digit in the decimal number has weight is a power of 10. Binary numbers are those numbers whose base value is 2. Binary numbers are also known as base-16 number system which contain only two number 1 and 0. Here, the position of every ... Read More

Swift program to print 8 star pattern

Ankita Saini
Updated on 13-Dec-2022 13:24:31

180 Views

This tutorial will discuss how to write swift program to 8 star pattern. Star pattern is a sequence of “*” which is used to develop different patterns or shapes like pyramid, rectangle, cross, etc. These star patterns are generally used to understand or practice the program flow controls, also they are good for logical thinking. To create a 8 star pattern we can use any of the following methods − Using nested for loop Using stride Function Below is a demonstration of the same − Input Suppose our given input is − Num = 5 Output The ... Read More

Swift program to print pascal’s triangle

Ankita Saini
Updated on 13-Dec-2022 16:33:25

306 Views

This tutorial will discuss how to write swift program to print Pascal’s triangle. A pascal’s triangle is a triangular array of the binary coefficient. It is a never ending equilateral triangle which always follows the rule of adding two numbers from the above row to get the number of below row. For example, the initial number of first row is 1 so the number of 2nd row is the sum of two numbers of the 1st row that are 0+1 and 1+0, so we get [1, 1]. Now the number of 3rd rows is the sum of the two numbers ... Read More

Swift program to find the GCD of two given numbers using recursion

Ankita Saini
Updated on 13-Dec-2022 11:57:40

302 Views

This tutorial will discuss how to write swift program to find the GCD of two given numbers using recursion. GCD(Greatest Common Factor) of two numbers is known as the greater positive number which is the common factor of both the given two positive numbers. GCD is also known as HCF(Highest Common Factor). GCD of two numbers cannot be negative or zero and the minimum GCD value of two numbers is always 1. For example, suppose we have two numbers: 16 and 24 So the factor of 16 = 2x2x2x2 The factor of 24 = 2x2x2x3 So, GCD(16, 24) = 2x2x2x2 ... Read More

Swift program to find the reverse of a given number using recursion

Ankita Saini
Updated on 13-Dec-2022 11:47:35

359 Views

This tutorial will discuss how to write swift program to find the reverse of a given number using recursion. Reversing a number is a process in which the position of the digits of a number is interchanged to reverse their order. To find the reverse of the number we use recursive approach. Recursive approach is an approach in which a function call itself to complete the specified task. Below is a demonstration of the same − Input Suppose our given input is − MyVal = 278938 Output The desired output would be − Reverse number = 839872 Method ... Read More

Swift program to display prime numbers between intervals using function

Ankita Saini
Updated on 13-Dec-2022 11:42:02

141 Views

This tutorial will discuss how to write swift program to display prime numbers between intervals using function. Prime numbers are those numbers that are greater than 1 and has exactly two factors that is 1 and the number itself. For example, 7 is the prime number because it has only two factors that are 1 and 7. Below is a demonstration of the same − Input Suppose our given input is − Lower Interval = 18 Upper Interval = 42 Output The desired output would be − Prime numbers between 18 to 42 are 19 23 29 31 37 ... Read More

Advertisements