This post implements the simplest subtraction operation using OC, which includes concepts such as variable definition, operation method, and formatted output. The main learning basic grammar, in fact, and the C language syntax is still more similar.
The exact code is just written in the main method. The detailed code is as follows:
#import <Foundation / Foundation.h>
int main (int argc, const char * argv []) {
@autoreleasepool {
int a = 4; // Define variables and assign values;
int b = 2;
int add = a + b; // addition operation;
int sub = a-b; // Subtraction;
int mul = a * b; // multiplication;
int div = a / b; // divide;
NSLog (@ "add =% d", add); // output the result;
NSLog (@ "sub =% d", sub);
NSLog (@ "mul =% d", mul);
NSLog (@ "div =% d", div);
}
return 0;
}
The final output results are as follows:
。
In conclusion, the best way for us to learn is to study the unknown knowledge according to the knowledge we have learned before, so as to Sichun and improve the learning efficiency.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Objective-c Study Notes (iv)--OC to achieve the simplest mathematical operations