A "Hello World" for too many languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

swapVariable.m 1.5KB

  1. #import <Foundation/Foundation.h>
  2. /* "Swapping two variables"
  3. *
  4. * Ever had that one time when you thought "I want to write a mobile app!" This was me 4 years ago. Of course, I started with iOS,
  5. * or more accurately, Objective-C. I don't really like it, to be frank.
  6. *
  7. * It was too different from C and, at the time, I didn't have a Mac to code on or a virtualenv for Xcode to run in. So, in the end, I ended up
  8. * coding a simple little app from scratch. Needless to say, I didn't particularly like it, since there was no solid support for it at
  9. * the time. In the end, I kind of quit trying to do mobile for a while, eventually coming back to Android. "Must be easier, right?"
  10. * Eh, not by much.
  11. *
  12. * You see, back then, mobile apps required a butt-load of GUI support to easily code an UI for the mobile application. These days, it's
  13. * a lot better, but I still don't find myself coding GUI's too much. Thank God for Electron or Visual Studio when I *really* need a quick
  14. * UI.
  15. *
  16. * This algorithm simply swaps two integer variables by not using a third variable. It does this by storing the sum of two numbers in one
  17. * variable, then substracting in order to "swap" the variables.
  18. */
  19. int main(int argc, const char * argv[]) {
  20. @autoreleasepool {
  21. printf("Hey, guy! Gimme two numbers: ");
  22. int a, b;
  23. scanf("%i %i", a, b);
  24. a = a + b;
  25. b = a - b;
  26. a = a - b;
  27. printf("Done! Here are the two numbers: %i %i", a, b);
  28. }
  29. return 0;
  30. }