一段代碼開始新的學習
//// main.m// Demo1//// Created by lee on 14/10/27.// Copyright (c) 2014年 lee. All rights reserved.//#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { int quotient, numertor, denominator; numertor = 10; denominator = 2; quotient = numertor/denominator; NSLog(@"The fraction is %i/%i /nthe quotient is %i", numertor, denominator, quotient); } return 0;}
1.int quotient, numertor, denominator;
定義整形的變量,object-c中常見數據類型如下:
1.1 整型 int integerType = 1;
1.2 浮點型 float floatType = 3.14;
1.3 雙浮點型 double doubleType = 3.1415;
1.4 短整型 short int shortType = 50;
1.5 長整型 long long int longlongType = 123456789L;
2.quotient = numertor/denominator;
變量相除(numertor/denominator)然后將得到的值賦給商(quotient)
3.NSLog(@"The fraction is %i/%i /nthe quotient is %i", numertor, denominator, quotient);
NSLog中%i的使用方法與C語言中相同,即只要在NSLog的例程中發現%i字符,會自動用例程中的對應變量替換顯示。/n為換行符。
程序運行結果如下:
2014-10-27 21:30:48.556 Demo1[1521:67965] The fraction is 10/2 the quotient is 5PRogram ended with exit code: 0
|
新聞熱點
疑難解答