標籤:
//// main.m// LessonBasic//// Created by laouhn on 15/7/14.// Copyright (c) 2015年 David. All rights reserved.//#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { void test5(); test5(); return 0;}void test5(){ //控制台輸入一個字元,接收,並輸出 char a = ‘a‘; printf("請輸入一個字元:"); scanf("%c",&a); printf("a=%c",a);}void test4(){ int a = 4; short b = 5; long c = 6; float e = 7.00; char f= ‘a‘; printf("a = %d,b=%hd,c=%ld,e=%f,f=%c\n",a,b,c,e,f); printf("%-4d,%d\n",1,2); printf("%04d\n",1); printf("請輸入一個整數:"); scanf("%d",&a); printf("a = %d\n",a);}void test3(){ printf("Hello,world !\n"); int a = 3; int b = 5; printf("a + b = %d\na -b = %d\na * b = %d\na / b = %d\n a %% b = %d",a + b,a - b,a * b,a / b,a % b); }void test2(){ int a = 4; int b = 5; int c = b; b = a; a = c; printf("a = %d,b = %d",a,b); int a1 = 12; int a2 = 15; a1 =a2+a1; a2=a1-a2; a1=a1-a2; printf("a1 = %d,a2 = %d",a1,a2);}void test1(){ //匯入標頭檔有兩種形式:<>,"" //<>作用:匯入系統檔案 //""作用:匯入別人寫好的檔案 //資料類型:作用,規定資料的類型,以及大小 //‘0‘-----‘9‘ 對應 48----57 //‘A‘--- ‘B‘ 對應 65----90 //‘a‘----‘z‘ 對應 97----122 //‘A‘+32=‘a‘ /* 1. 基礎資料型別 (Elementary Data Type) :整形,浮點型 整形:long 32位系統中4個位元組,64位系統中8個位元組, int 4個位元組 short 2個位元組 char 1個位元組 浮點型:單精確度浮點型float 4個位元組 雙精確度浮點型double 8個位元組 2.常量:不受外力作用情況下,不會被改變的量 整形常量:9527,22,56 浮點型常量:3.1415926 字元型常量:‘9‘,‘1‘,‘A‘,‘m‘ 3.變數定義:資料類型 變數名 = 初值; int age = 27;//變數定義,一定要刷碗(賦初值) char age=‘a‘; float age=2.3; double age=2.33; 4.變數名命名規則: 1.由數字,字母,底線組成,並且數字不能開頭 2.不能與系統關鍵字重名 3.不能與其它變數名重名 4.見名知意 5.運算子 賦值運算子:"=",把等號右邊的值,付給等號左邊的變數 賦值的過程,市拷貝的過程,將等號右邊的值,拷貝一份,賦給等號左邊的值 算術運算子:+,-,*,/,++,-- 6.運算式 :可以由 常量 ,變數,運算子組成 怎樣判斷是不是運算式:有沒有值! int a = 3; int b = 5; a + 3; a + b; //語句:以分號 ";",結尾 7.格式化輸出函數 int a = 3; int b = 5; printf("a + b = %sd\na -b = %d\na * b = %d\na / b = %d\n a %% b = %d",a + b,a - b,a * b,a / b,a % b); 格式化輸出的目的是驗證 7.1轉化符: %d ---- int %hd -- short %ld -- long %f -- float,double %c---- char 7.2轉義符: %% // printf("%-4d,%d\n",1,2);//靠左對齊 printf("%04d\n",1);//靠右對齊 8.格式化輸入函數 控制台輸入一個整數,並且進行接收 首先,定義一個變數,什麼類型的變數呢?與輸入類型相同的變數 int a = 0; scanf(); */ //變數初始化後使用 char age = ‘a‘; float age1 = 2.3; double age2 = 2.33; NSLog(@"%f",age2+(double)2); age = ‘1‘; age1 = 4.2; age2 = 23.33;// int a =3;// int b = 4;// int sum = a + b;// int sub =a - b;// int mul = a * b;// int divi = a / b;// int rem = a % b;// printf("divi = %d,rem = %d",divi,rem);//注意 ,取餘的兩端的數必須是整型變數 int a = 3; int b = 5; a++; //等價於 a = a + 1; ++a; //複合運算子:+=,-=,*=,/=,%= a += b;//等價與 a = a + b; b += a; a -= b; b -= a; a *= b; //等價於 a = a * b; a /= b; //等價於 a = a / b; a %= b; //等價於 a= a % b; //a + 0; }
iOS中的c第一天