Skip to content

Instantly share code, notes, and snippets.

@sodastsai
Created October 2, 2016 06:17
Show Gist options
  • Save sodastsai/17a4686e187436ee011c891e29f87eba to your computer and use it in GitHub Desktop.
Save sodastsai/17a4686e187436ee011c891e29f87eba to your computer and use it in GitHub Desktop.
divide function for Swift's argument labels
#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;
}
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)")
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