Found 517 Articles for Swift

Swift Program to Generate Multiplication Table

Ankita Saini
Updated on 01-Aug-2022 12:43:54

803 Views

This tutorial will discuss how to write a Swift program to generate Multiplication Table. A multiplication table is a list or table of multiples of a specified number. We can create a multiplication table by multiplying a number with whole numbers. Generally, a multiplication table is created upto 10 times but you can create it according to your need. Below is a demonstration of the same − Suppose our given input is − The desired output is − Following is the multiplication table is 9 9 * 1 = 10 9 * 2 = 20 9 * 3 ... Read More

Swift Program to Calculate Simple Interest

Ankita Saini
Updated on 04-Aug-2022 08:10:43

778 Views

This tutorial will discuss how to write a swift program to calculate simple interest. Simple interest is the most commonly used method to find the interest on the money for a given time period. In this method, the interest is always applied to the original principal amount with same the interest rate for every time period. It is calculated by multiplying the interest rate by the principal amount and the time. Formula Following is the formula of simple interest − S.I = Principal Amount(P) x Time(T) x Rate(R)/100 Where Principal(P) − Principal amount represents the amount that is initially invested. ... Read More

Swift Program to Calculate the Power of a Number

Ankita Saini
Updated on 01-Aug-2022 09:26:18

1K+ Views

This tutorial will discuss how to write a swift program to calculate the power of a number. Power of a number means how many times a number is used in multiplication, for example, 16 ^2 = 16 * 16 = 256 or 16 to the power of 2. It is also known as exponent or indices. Below is a demonstration of the same − Suppose our given input is − Number - 16 Exponent Value is - 3 The desired output is − Final result is 16^3 = 4096 Calculating power of a number using recursion We can calculate the ... Read More

How to Swap Two Numbers in Swift Program?

Ankita Saini
Updated on 29-Jul-2022 10:28:13

2K+ Views

This tutorial will discuss how to write a swift program to swap two numbers. Swapping of two variables means mutually exchanging the values of two variables.Swapping using temporary variableGiven two variables Number1 and Number2 now we swap their values with each other using a temporary variable Numtemp. It is the most easiest way to swap two numbers.AlgorithmThe algorithm is explained below −Step 1 − Declare three integer variables: Number1, Number2 and Numtemp(temporary variable.)Step 2 − Assign values to Number1 and Number2Step 3 − Assign Number1 to NumbertempStep 4 − Assign Number2 to Number1Step 5 − Assign Numbertemp to Number2Step 6 ... Read More

How to Read The Number From Standard Input in Swift Program?

Ankita Saini
Updated on 28-Jul-2022 12:40:08

1K+ Views

This tutorial will discuss how to write a swift program to read the number from standard input. Reading a number from standard input in Swift is very easy with the help of readLine(), Int(), and Float() functions.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 to the EOF when the readLine() function is called then this method will return nil.SyntaxFollowing is the syntax of Swift readLine() function −readLine(strippingNewline: true) Or readLine()Int() function − This function is used ... Read More

Swift Program to Multiply Two Floating-Point Numbers

Ankita Saini
Updated on 28-Jul-2022 09:40:01

537 Views

This tutorial will discuss how to write a swift program to multiply two floating point numbers.Floating point numbers are the numbers with fraction or numbers with decimal value for example 34.56, 987.23, 0.234, etc. In Swift, floating point data type has a wide range of values and can store much smaller or larger number as compare to Integer. Swift support two signed floating point number types that is Double and Float. Double is used to represent 64-bit floating point number and has precision of at least 15-decimal digit. Whereas Float is used to represent 32-bit floating point number and has ... Read More

How to Print an Integer in Swift Program?

Ankita Saini
Updated on 28-Jul-2022 09:26:11

1K+ Views

This tutorial will discuss how to write a swift program to print an Integer. Integers represents the number with no fractional component like 45, 980, -234, 24, etc. Swift supports both signed as well as unsigned integers in 8, 16, 32, and 64 bit. Here signed integer is represented by Int whereas unsigned integer is represented by UInt and their size is same as the current platform e.g if the platform is 32-bit then the size is Int32 or UInt32 unless you work with some specific size of the integer.SyntaxFollowing is the syntax for creating integer type variablevar x : ... Read More

Swift Program to Find the Area of a Circle

Ankita Saini
Updated on 29-Jul-2022 10:10:06

796 Views

This tutorial will discuss how to write a swift program to find the area of a Circle.In a circle, an area is known as the space that is enclosed inside the boundaries of the circle in the two-dimensional plane. Suppose we have a round tea table now the area of the circle helps us to find how much cloth we required to cover the top of the table. We can calculate the area of the circle with the help of the radius or diameter, here, We are going to use the formula of area of the circle −Area of the ... Read More

Swap Numbers without using temporary variable in Swift Program?

Ankita Saini
Updated on 29-Jul-2022 10:07:16

14K+ Views

This tutorial will discuss how to write a swift program to swap two numbers without using temporary variable. Swapping of two variables means mutually exchanging the values of two variables.Swapping two numbers without using temporary variablesGiven two variables Number1 and Number2 now we swap their values without using any temporary variable. Here we use tuple to preform the swapping operation.AlgorithmThe algorithm is explained below −Step 1 − Declare two integer variables − Number1, and Number2Step 2 − Assign values to Number1 and Number2Step 3 − Use tuple syntax to swap −(Number1, Number2) = (Number2, Number1)Step 4 − Display the value ... Read More

How to Add two Numbers in Swift Program?

Ankita Saini
Updated on 29-Jul-2022 09:53:04

3K+ Views

This tutorial will discuss how to write a swift program to add two numbers.Adding two numbers in Swift language is simple and can be performed with the help of the addition arithmetic operator(+). The arithmetic addition operator (+) uses two numbers as operands and returns their sum as output.In this operator, both the operands should be of the same data types, For example swift allows adding a float into float without an issue but if we will try to add different types of data types using (+) operator then the compiler will raise an error, For example adding an Int ... Read More

Advertisements