Created
January 30, 2016 17:21
-
-
Save mominul/f1d747b5d96b8c935e1d to your computer and use it in GitHub Desktop.
Swift: Get remainder in a Integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Calculates remainder in a integer | |
| // It's work like the '%' operator in swift | |
| // Currently integer values are supported | |
| // Public Domain ;) | |
| // By Muhammad Mominul Huque | |
| func getRemainder(var realNum: Int, goesTo: Int) ->Int { | |
| while(realNum > goesTo) { | |
| realNum -= goesTo | |
| } | |
| return realNum | |
| } | |
| var rel1 = getRemainder(9, goesTo: 4) | |
| var rel2 = 9 % 4 | |
| print("\(rel1) is equal to \(rel2)") | |
| assert(rel1 == rel2) | |
| /* It's my first program in swift! */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment