Chapter 15 : Arithmetic Operators

Topics Covered :

1. What are Arithmetic Operators
2. - Subtraction
4. * Multiplication
5. / Division
6. % Modulus
7. Examples

# Arithmetic Operators

Arithmetic operators are the nothing but simple addition, subtraction, multiplication and division operators that we use in our day to day life for basic calculations

Swift Supports 5 types of Arithmetic Operators

- Subtraction Operator

* Multiplication Operator

/ Division Operator

% Remainder/Remainder Operator

#### Subtraction Operator (-)

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Subtraction Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 30
var b = 20

println(a-b)
println(b-a)

```
```
Output :

10
-10
Program ended with exit code: 0

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//
//  Created by Code2care on 16/09/14.
//

var a = 30
var b = 20
var c = "Hello!! "
var d = "World"
var e = "O"
var f = "K"

println(a+b)

//Concatenating String's using + Operator
println(c+d)

//Concatenating Character's using + Operator
println(e+f)

```
```
Output :

50
Hello!! World
OK
Program ended with exit code: 0

#### Multiplication Operator (*)

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Multiplication Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 30
var b = 20
var c = -40

println(a*b)
println(c*b)

```
```
Output :

600
-800
Program ended with exit code: 0

#### Division Operator (/)

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Division Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 32.20
var b = 22.55
var c = -9.29

println(a/b)
println(c/b)

```
```
Output :

1.42793791574279
-0.411973392461197
Program ended with exit code: 0

#### Remainder Operator (%)

% is called as Remainder Operator,

Syntax : numberA % numberB

Remainder operator is also known as Modulo operator in major other languages , but in Swift for negative numbers it works as a remainder instead of modulo.

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Remainder Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 20
var b = 10
var c = -6

println(a%b)
println(c%b)

```
```
Output :

0
-6
Program ended with exit code: 0