Created
October 2, 2016 06:17
-
-
Save sodastsai/17a4686e187436ee011c891e29f87eba to your computer and use it in GitHub Desktop.
divide function for Swift's argument labels
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
#include <iostream> | |
typedef struct { | |
int quotient; | |
int remainder; | |
} DivideResult; | |
DivideResult divide(int dividend, int divisor) { | |
return (DivideResult){.quotient=dividend/divisor, .remainder=dividend%divisor}; | |
} | |
int main(int argc, const char *argv[]) { | |
DivideResult result = divide(22, 7); | |
std::cout << "22/7=" << result.quotient << "..." << result.remainder << std::endl; | |
return 0; | |
} |
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
func divide(dividend: Int, divisor: Int) -> (quotient: Int, remainder: Int) { | |
return (dividend/divisor, dividend%divisor) | |
} | |
let result = divide(dividend: 22, divisor: 7) | |
print("22/7=\(result.quotient)...\(result.remainder)") |
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
func divide(_ dividend: Int, by divisor: Int) -> (quotient: Int, remainder: Int) { | |
return (dividend/divisor, dividend%divisor) | |
} | |
let result = divide(22, by: 7) | |
print("22/7=\(result.quotient)...\(result.remainder)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment