一段代码开始新的学习
// // 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 5 Program ended with exit code: 0
时间: 2024-10-07 12:08:44