Browse Source

Add Objective-C to list

master
Matei-Alexandru Gardus 9 months ago
parent
commit
f259de3561
No known key found for this signature in database
2 changed files with 34 additions and 1 deletions
  1. 2
    1
      README.md
  2. 32
    0
      swapVariable.m

+ 2
- 1
README.md View File

@@ -7,4 +7,5 @@ This is a Git repository of elementary algorithm programs for every language I k
7 7
 ## Programming Languages List
8 8
 - C
9 9
 - C++
10
-- C#
10
+- C#
11
+- Objective-C

+ 32
- 0
swapVariable.m View File

@@ -0,0 +1,32 @@
1
+#import <Foundation/Foundation.h>
2
+
3
+/* "Swapping two variables"
4
+ *
5
+ * 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,
6
+ * or more accurately, Objective-C. I don't really like it, to be frank.
7
+ *
8
+ * 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
9
+ * 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
10
+ * 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?"
11
+ * Eh, not by much.
12
+ *
13
+ * 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
14
+ * 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
15
+ * UI.
16
+ *
17
+ * 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
18
+ * variable, then substracting in order to "swap" the variables.
19
+ */
20
+
21
+int main(int argc, const char * argv[]) {
22
+    @autoreleasepool {      
23
+        printf("Hey, guy! Gimme two numbers: ");
24
+        int a, b;
25
+        scanf("%i %i", a, b);
26
+        a = a + b;
27
+        b = a - b;
28
+        a = a - b;
29
+        printf("Done! Here are the two numbers: %i %i", a, b);
30
+    }
31
+    return 0;
32
+}

Loading…
Cancel
Save