-
Notifications
You must be signed in to change notification settings - Fork 23
/
Contents.swift
48 lines (43 loc) · 2.08 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*:
## Exercise - Basic Arithmetic
You decide to build a shed and want to know beforehand the area of your yard that it will take up. Create two constants, `width` and `height`, with values of 10 and 20, respectively. Create an `area` constant that is the result of multiplying the two previous constants together, and print out the result.
*/
let width = 10
let height = 20
let area = width * height
print(area)
/*:
You decide that you'll divide your shed into two rooms. You want to know if dividing it equally will leave enough room for some of your larger storage items. Create a `roomArea` constant that is the result of dividing `area` in half. Print out the result.
*/
let roomArea = area / 2
print(roomArea)
/*:
Create a `perimeter` constant whose value equals `width` plus `width` plus `height` plus `height`, then print out the result.
*/
let perimeter = width + width + height + height
print(perimeter)
/*:
Print what you would expect the result of integer division of 10 divided by 3 to be. Create a constant, `integerDivisionResult` that is the result of 10 divided by 3, and print the value.
*/
print(3)
let integerDivisionResult = 10 / 3
print(integerDivisionResult)
/*:
Now create two constants, `double10` and `double3`, set to 10 and 3, and declare their types as `Double` values. Declare a final constant `divisionResult` equal to the result of `double10` divided by `double3`. Print the value of `divisionResult`. How does this differ from the value when using integer division?
*/
let double10: Double = 10
let double3: Double = 3
let divisionResult = double10 / double3
print(divisionResult) // Division more precise
/*:
Given the value pi (3.1415927), create a `radius` constant with a value of 5.0, then calculate the diameter and circumference of the circle using the following equations, and print the results:
*diameter = 2 * radius*
*circumference = 2 * pi * radius.*
*/
let pi = 3.1415927
let radius = 5.0
let diameter = 2 * radius
let circumference = 2 * pi * radius
print(diameter)
print(circumference)
//: page 1 of 8 | [Next: App Exercise - Fitness Calculations](@next)