C/C++基礎程式設計班

Size: px
Start display at page:

Download "C/C++基礎程式設計班"

Transcription

1 C/C++ 基礎程式設計 我們必須讓小事也令人難忘 We ve got to make the small things unforgettable. -Steve Jobs 函式 (Function) 講師 : 張傑帆 CSIE NTU

2 課程大綱 函式概論 變數類型 - 全 / 區域變數 函式中以指標當參數 傳遞陣列參數 把程式拆成多個檔案

3 函式 (Function) 包函許多程式碼的一行程式 ( 用來代表某種功能 ) 當程式碼太多且會重覆出現時, 可以將部份程式碼抽離主程式, 寫成一段函式, 有需要用到時再去呼叫它 之前我們已經使用過 C 語言提供的函式, 現在我們要練習自己寫個函式來使用 內建函式 : main() /printf()/scanf() 也是函式, 這些都是系統提供的

4 函式的宣告 宣告一個函式並寫裡面的程式 要訣 : 取個函式名稱用來代表某個功能 函式名稱 這個功能需要給他什麼資料才能執行 參數 開始寫函式內的程式碼 程式碼 執行完後會回傳什麼資料給呼叫函式的程式 回傳值 函式內的變數是獨立的, 只有在函式內可以使用 回傳值資料型態 ( 不需回傳可用 void) 資料型態函式名稱 ( 資料型態參數 1, 資料型態參數 2,, 資料型態參數 n) 程式碼 ; return 回傳值 ; 傳入函式值資料型態 int func ( int var1, int var2) int var3 = var1+var2; return var3;

5 寫好的函式要放在哪裡呢? 由於使用者自定函式是無中生有的, 因此必須在使用前先定義該函式, 此即為該函式的主體 函式主體的位置通常撰寫在 #include 和 main() 主函式的之間, 即 main() 主函式的前面, 也允許放在 main() 主函式的後面, 若使用後者就必須在 main() 主函式前面先宣告函式的原型, 以告知編譯器此自定函式在程式中有定義 int func ( int var1, int var2) int var3 = var1+var2; return var3;

6 int func ( int, int ); int func ( int var1, int var2) int var3 = var1+var2; return var3; int func ( int var1, int var2) int var3 = var1+var2; return var3;

7 int func ( int, int ); int func ( int var1, int var2) int var3 = var1+var2; return var3;

8 8

9 函式的使用練習 宣告完的函式即可在其他函式或主程式 main 中呼叫並使用 下面 hello 為一個不需參數也不會回傳資料的函式 : #include <stdio.h> void hello(); // hello 函式的宣告 int main() printf(" 準備呼叫 hello()\n"); hello(); // 呼叫 hello 函式 printf(" 已呼叫過 hello()\n"); return 0; void hello() // hello 函式的程式碼 (void 代表不回傳資料 ) printf("hello\n"); printf("hello\n"); printf("hello\n");

10 (parameter) (argument)

11 函式的使用 : 參數與回傳值 要訣 : 資料傳遞需要先儲存! 參數 : 函式宣告儲存單元將傳入的值儲存 回傳值 : 函式將結果回傳給呼叫它的地方儲存 範例 : 使用函式計算數學公式 F(x, y) = 2x + y 90 F: 給定 x, y 兩值即可得 2x+y 之結果 #include <stdio.h> int F(int x, int y); int main() int num1, num2, ans; scanf("%d%d", &num1, &num2); ans = F(num1, num2); printf("f(%d, %d) = %d\n", num1, num2, ans); return 0; int F(int x, int y) int z = 2*x + y; return z;

12 函式的參數 - 傳值呼叫 (Call by value) 呼叫用的參數內容會被 copy 到函式用來接收參數的變數中, 也就是說, 呼叫時要傳入的參數, 和函式中接收用的參數, 事實上是兩個不同的變數 所以函式中改變參數數值時, 原來呼叫處的數值並不會改變 可以想像說, 函式中的參數會宣告成一個新的變數, 而它的初值會在呼叫時被設定成傳入的數值 執行程式後可以發現, 每個變數的記憶體位址都不一樣, 所以當然每個變數都是各自獨立的

13 函式的參數 : 易混淆的例子 範例 #include <stdio.h> void func(int i); int main() // 這裏的變數跟上面都沒有關係 int a=3; int b=2; int i=4; func(i); printf("%d %d %d\n",a,b,i); // 有沒有發現, 執行 func 的 i=5 後, 這裏的 i 仍然為 4 return 0; void func(int i) int a=2; int b=3; i=5; printf("%d %d %d\n",a,b,i);

14 在函式中結束程式 : exit(0); 在函式中如果要強制結束程式可以使用 exit 函式 #include <stdio.h> #include <stdlib.h> void func(); int main() func(); printf(" 這行不會印出 \n"); return 0; void func() printf(" 呼叫 exit 函式!\n"); exit(0);

15 練習 寫一個計算 n 的函式 int sum(int n);

16 課程大綱 函式概論 變數類形 - 全 / 區域變數 函式中以指標當參數 傳遞陣列參數 把程式拆成多個檔案

17 全域變數與區域變數 C 語言將函式內所宣告的變數稱為區域變數 (Local Variable), 此類變數的有效範圍僅在該函式內, 離開該函式便由記憶體中釋放掉, 下次呼叫該函式時再重新配置記憶體給該函式使用 C 語言另外提供一種變數可供多個函式共同使用, 變數的有效時間一直到程式結束為止, 我們將此類的變數稱為 全域變數 (Global variable)

18 局部 / 區域變數 (Local Variable) 自動變數只在它所定義的區塊內有效 只要在變數所屬的區塊結構內執行, 該變數的資料是有效而正確的 當程式執行離開了該區塊, 所有於區塊內定義的 自動變數就不存在了 #include <stdio.h> void func(); int main() int x=1; func(); func(); printf("%d\n",x); return 0; x 2=>3 x x x x void func() int x=2; x = x + 1; printf("%d\n",x); 2=>3

19 區域變數的名稱可以重複使用 在不同函數內被宣告的區域變數就代表是 2 個不同的變數 21

20 全域變數 (Global Variable) 全域變數的有效範圍不是區域性, 而是整體性 變數定義在任何函數的外面, 表示可以被其他函數所共用 x #include <stdio.h> int x = 5; void func(); int main() func(); func(); printf("%d\n",x); return 0; x void func() x = x + 1; printf("%d\n",x); x

21 程式中區域變數與全域變數的名稱相同, 當存取函式內的變數時會以區域變數為優先, 使用時最好注意, 建議全域變數最好不要和區域變數的名稱重複, 以免參用時造成混淆 函數內的全域變數會被區域變數掩蓋掉

22 小練習 排列組合 24

23 課程大綱 函式概論 變數類別 函式中以指標當參數 傳遞陣列參數 把程式拆成多個檔案

24 傳址呼叫 call by address 所謂的 傳址呼叫 就是函式在做引數傳遞時, 呼叫函式中的實引數是將自己本身的記憶體位址傳給被呼叫函式內的引數 希望將回傳一個以上的結果時使用 傳址呼叫的設定方式是 : 定義的函式小括號內的虛引數必須宣告為指標變數 ( 即在變數前面加上 ) 呼叫函式內的引數必須傳送變數的記憶體位址 ( 即變數前面加上 &)

25 函式中以指標當參數 - 傳址呼叫 要是函式傳參數時, 傳的是變數的位址, 就可以在函式中去改變主程式中變數的內容了 範例 : swap, 兩變數資料交換 #include <stdio.h> void swap(int *, int *); int main() int num1 = 5; int num2 = 10; swap(&num1, &num2); printf("num1=%d\n", num1); printf("num2=%d\n", num2); return 0; void swap(int *px, int *py) int temp; 0x1000 0x1004 temp = *px; *px = *py; *py = temp;

26 傳值呼叫 call by value 若是想要定義交換引數 x 與 y 的 swap 函數, 就不能使用傳值的方式來傳遞引數, 因為傳值只是傳遞引數中的值而已, 並不會對引數本身產生改變, 所以只會交換參數

27 小練習 請試寫一函式可加總 1 到 n 和計算 n! 並利用指標同時將兩個結果送給原呼叫函式 void sum_fact( int n, int *sum, int *fact);

28 課程大綱 函式概論 變數類別 函式中以指標當參數 傳遞陣列參數 把程式拆成多個檔案

29 傳遞陣列參數 把陣列當參數來傳遞時, 要從記憶體的角度來看, 如果傳遞的只是陣列某欄位中的一個變數, 那和傳普通變數沒有什麼分別 Ex: int ary[5] = 1,2,3,4,5; func(ary[0]); 如果傳的是整個陣列, 傳遞的東西會是陣列的位址 Ex: int ary[5] = 1,2,3,4,5; func(ary);

30 傳遞陣列參數 範例 #include <stdio.h> #include <stdlib.h> void output(int n, int *p); int main() int a[5] = 1,2,3,4,5; int b[7] = 1,2,3,4,5,6,7; output(5, a); output(7, b); return 0; void output(int n, int *p) int i; for(i=0; i<n; i++) printf("%d ",p[i]); printf("\n"); void printary(int n, int *P);

31 傳遞陣列參數 : 平均值計算 寫一個回傳同學成績平均分數之函式 #include <stdio.h> #include <string.h> double average(int student, int *score); double average(int student, int *score) int i; double sum=0; double aver; for(i=0; i<student; i++) sum+=score[i]; aver = sum/student; return aver; int main() int student; int *score; double aver; int i; printf(" 請輸入學生人數 : "); scanf("%d", &student); score = (int *)malloc(sizeof(int) * student); for(i=0; i<student; i++) printf(" 學生 %d: ", i+1); scanf("%d", &score[i]); aver = average(student, score); printf(" 平均 : %.2lf 分 \n", aver); return 0;

32 練習 繼續上一範例, 寫一個回傳最高分成績位置之函式 void printary(int n, int *P); double Avg(int n, int *P); int MaxScore(int n, int *P);

33 傳遞陣列參數 : 字串處理 使用 upper 函式, 將字串中小寫英文轉大寫英文 #include <stdio.h> void upper(char *a); int main() char str[80]; gets(str); upper(str); printf("%s \n", str); return 0; void upper(char *a) int i=0; while(1) if(a[i]>='a' && a[i]<='z') a[i]-=32; else if(a[i] == '\0') break; i++;

34 課程大綱 函式概論 變數類別 函式中以指標當參數 傳遞陣列參數 把程式拆成多個檔案

35 把程式拆成多個檔案 要訣 : main.c 標頭檔.h 用來宣告函式名稱 ( 用來被 include) 程式檔.c 用來寫函式程式碼 ( 放到專案一起編譯與連結 ) #include <stdio.h> #include "hello.h" // hello() 的宣告在這裏面 int main() printf(" 準備呼叫 hello()\n"); hello(); // 呼叫 hello 函式 printf(" 已呼叫過 hello()\n"); return 0; #ifndef HELLO_H #define HELLO_H void hello(); // hello 函式的宣告 #endif #include "hello.h" #include <stdio.h> void hello() // hello 函式的程式碼 printf("hello\n"); printf("hello\n"); printf("hello\n"); hello.h hello.c

36 把程式拆成多個檔案 練習 : 將下述兩個函式分成 score.h 與 score.c, 並寫一個程式計算班上同學成績並列出平均與最高分 void printary(int n, int *P); double Avg(int n, int *P); int MaxScore(int n, int *P);

37 回家作業 - 質數判斷程式 請寫一函式令其可以判斷傳入參數是否為質數 int IsPrime(int num); 是質數的話回傳 1, 不是的話回傳 0 並將函式分成 prime.h prime.c 與 main.c

38 延申閱讀 static 靜態區域變數 函數指標 遞迴函式

PowerPoint 簡報

PowerPoint 簡報 Function and Data Structure 張傑帆 Chang, Jie-Fan 函數定義 函數傳遞參數與回傳值 區域變數與全域變數 包函許多程式碼的一行程式 ( 用來代表某種功能 ) 當程式碼太多且會重覆出現時, 可以將部份程式碼抽離主程式, 寫成一段函式, 有需要用到時再去呼叫它 函數是經過組織且可重複使用的程式碼, 是能用來實現單一或是相關聯的程式碼 巧妙的運用函數可以提高程式碼的重複利用率,

More information

Microsoft Word - ACL chapter02-5ed.docx

Microsoft Word - ACL chapter02-5ed.docx 第 2 章神奇的質數 2.1.1 什麼是質數 1 1 1 打下好基礎 - 程式設計必修的數學思維與邏輯訓練 1 1 0 10 2 3 5 7 4 6 8 9 10 4 10000 1229 1000 168 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131

More information

Microsoft PowerPoint - C_Structure.ppt

Microsoft PowerPoint - C_Structure.ppt 結構與其他資料型態 Janet Huang 5-1 結構的宣告 struct 結構名稱 struct 結構名稱變數 1, 變數 2,, 變數 m; struct 結構名稱 變數 1, 變數 2,, 變數 m; student; student; 5-2 1 結構變數初值的設定 struct 結構名稱 struct 結構名稱變數 = 初值 1, 初值 2,, 初值 n student="janet","1350901",100,95

More information

C/C++ - 函数

C/C++ - 函数 C/C++ Table of contents 1. 2. 3. & 4. 5. 1 2 3 # include # define SIZE 50 int main ( void ) { float list [ SIZE ]; readlist (list, SIZE ); sort (list, SIZE ); average (list, SIZE ); bargragh

More information

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc 2 5 8 11 0 13 1. 13 2. 15 3. 18 1 23 1. 23 2. 26 3. 28 2 36 1. 36 2. 39 3. 42 4. 44 5. 49 6. 51 3 57 1. 57 2. 60 3. 64 4. 66 5. 70 6. 75 7. 83 8. 85 9. 88 10. 98 11. 103 12. 108 13. 112 4 115 1. 115 2.

More information

chap07.key

chap07.key #include void two(); void three(); int main() printf("i'm in main.\n"); two(); return 0; void two() printf("i'm in two.\n"); three(); void three() printf("i'm in three.\n"); void, int 标识符逗号分隔,

More information

C++ 程式設計

C++ 程式設計 C C 料, 數, - 列 串 理 列 main 數串列 什 pointer) 數, 數, 數 數 省 不 不, 數 (1) 數, 不 數 * 料 * 數 int *int_ptr; char *ch_ptr; float *float_ptr; double *double_ptr; 數 (2) int i=3; int *ptr; ptr=&i; 1000 1012 ptr 數, 數 1004

More information

C/C++ Programming

C/C++ Programming 265 第九講 結構 講師 : 李根逸 (Ken-Yi Lee), E-mail: feis.tw@gmail.com 266 課程 大綱 結構 (struct) 結構宣告 [P.267] 結構定義 [P.268] 結構變數宣告 [P.269] 結構變數的初始化 [P.272] 存取結構成員 [P.244] 傳送 大型資料型態參數 [P.277] 267 結構宣告 結構是 一種衍 生的 自訂資料型態,

More information

運算子多載 Operator Overloading

運算子多載 Operator Overloading 函數樣板 (Function Template) 與 類別樣板 (Class Template) 講師 : 洪安 1 資料結構與 C++ 程式設計進階班 為何需要通用函數? (1/2) int abs(int x) { return (x>0)?x:-x; 取名困難不好記 float fabs(float x) { return (x>0)?x:-x; complex cabs(complex x)

More information

Microsoft PowerPoint - C_Language_flag4e_ch08.ppt [相容模式]

Microsoft PowerPoint - C_Language_flag4e_ch08.ppt [相容模式] 第八章 函數 認識函數與其原型 學習函數的宣告方式與定義 認識區域 全域與靜態變數 學習前置處理器的用法 1 8.1 簡單的函數範例 C 語言的函數 Top-down design 的目的是要達到逐步單純化 將大問題細分成小問題 將解決這些小問題的方法, 撰寫成較小的程式區塊 C 語言的函數 如賦予程式區塊一個名字 並且指定它的輸出與輸入 則此程式區塊就是一個 C 語言的函數 2 8.1 簡單的函數範例

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9 [P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10 C / C++ C C++ C C++ C++ C ( ) C++

More information

第3章.doc

第3章.doc 3 3 3 3.1 3 IT Trend C++ Java SAP Advantech ERPCRM C++ C++ Synopsys C++ NEC C C++PHP C++Java C++Java VIA C++ 3COM C++ SPSS C++ Sybase C++LinuxUNIX Motorola C++ IBM C++Java Oracle Java HP C++ C++ Yahoo

More information

Microsoft PowerPoint - C-Ch08.ppt

Microsoft PowerPoint - C-Ch08.ppt 函數 8-1 函數 函數 (function) 可以整合某些特定的處理 整合好的處理可以隨時呼叫使用 C 語言的程式本身也是一個函數, 也就是 main() 函數 使用函數可簡化程式 提款的處理 1. 將提款卡插入自動提款機當中 2. 輸入個人密碼 3. 指定提款金額 4. 領取款項 5. 確認款項與提款卡 提款處理 8-2 函數的定義與呼叫 定義函數的語法 : 傳回值的型態函數名稱 ( 引數列表

More information

840 提示 Excel - Excel -- Excel (=) Excel ch0.xlsx H5 =D5+E5+F5+G5 (=) = - Excel 00

840 提示 Excel - Excel -- Excel (=) Excel ch0.xlsx H5 =D5+E5+F5+G5 (=) = - Excel 00 Excel - - Excel - -4-5 840 提示 Excel - Excel -- Excel (=) Excel ch0.xlsx H5 =D5+E5+F5+G5 (=) = - Excel 00 ( 0 ) 智慧標籤 相關說明提示 -5 -- Excel 4 5 6 7 8 + - * / % ^ = < >= & 9 0 (:) (,) ( ) Chapter - :,

More information

Microsoft PowerPoint - 13_指標、資料傳遞2.pptx

Microsoft PowerPoint - 13_指標、資料傳遞2.pptx 1 2 指標 Lecture 13 指標函式呼叫的資料傳遞 (III) 傳址指標與陣列 Pointer 3 4 指標 / 指位器 (Pointer) 變數 int a; 整數型別, 名稱為 a 變數是為了使用記憶體資源來儲存資料與進行運算 所有的變數都佔有記憶體空間 記憶體 可視為一個很大的一維陣列, 單位是 byte 問題 一個 4KB 的電腦, 其記憶體位置 ( 編號 ) 從 0 至? 4 x

More information

資料結構之C語言重點複習

資料結構之C語言重點複習 鏈結串列自編教材 ( 一 ) 本教材 ( 一 ) 目標問題 : 每次以亂數產生一 [0,1000] 之整數值, 若該值 >100, 則以同方式繼續產生下一亂數值, 若該值

More information

CHAPTER VC#

CHAPTER VC# 1. 2. 3. 4. CHAPTER 2-1 2-2 2-3 2-4 VC# 2-5 2-6 2-7 2-8 Visual C# 2008 2-1 Visual C# 0~100 (-32768~+32767) 2 4 VC# (Overflow) 2-1 2-2 2-1 2-1.1 2-1 1 10 10!(1 10) 2-3 Visual C# 2008 10! 32767 short( )

More information

!249 第 八講 進階指標 講師 : 李根逸 (Ken-Yi Lee),

!249 第 八講 進階指標 講師 : 李根逸 (Ken-Yi Lee), 249 第 八講 進階指標 講師 : 李根逸 (Ken-Yi Lee), E-mail: feis.tw@gmail.com 250 課程 大綱 陣列的複製 [P.252] 字串的特殊性 [P.255] const 修飾字 [P.256] 指標陣列 [P.257] 字串陣列 [P.258] 指標與 二維陣列 [P.260] 動態記憶體配置與釋放 C 語 言中動態記憶體的配置 [P.266] C 語

More information

C/C++语言 - 运算符、表达式和语句

C/C++语言 - 运算符、表达式和语句 C/C++ Table of contents 1. 2. 3. 4. C C++ 5. 6. 7. 1 i // shoe1.c: # include # define ADJUST 7. 64 # define SCALE 0. 325 int main ( void ) { double shoe, foot ; shoe = 9. 0; foot = SCALE * shoe

More information

C/C++ - 文件IO

C/C++ - 文件IO C/C++ IO Table of contents 1. 2. 3. 4. 1 C ASCII ASCII ASCII 2 10000 00100111 00010000 31H, 30H, 30H, 30H, 30H 1, 0, 0, 0, 0 ASCII 3 4 5 UNIX ANSI C 5 FILE FILE 6 stdio.h typedef struct { int level ;

More information

untitled

untitled A, 3+A printf( ABCDEF ) 3+ printf( ABCDEF ) 2.1 C++ main main main) * ( ) ( ) [ ].* ->* ()[] [][] ** *& char (f)(int); ( ) (f) (f) f (int) f int char f char f(int) (f) char (*f)(int); (*f) (int) (

More information

nooog

nooog C : : : , C C,,, C, C,, C ( ), ( ) C,,, ;,, ; C,,, ;, ;, ;, ;,,,, ;,,, ; : 1 9, 2 3, 4, 5, 6 10 11, 7 8, 12 13,,,,, 2008 1 1 (1 ) 1.1 (1 ) 1.1.1 ( ) 1.1.2 ( ) 1.1.3 ( ) 1.1.4 ( ) 1.1.5 ( ) 1.2 ( ) 1.2.1

More information

untitled

untitled Introduction to Programming ( 數 ) Lecture 3 Spring 2005 March 4, 2005 Lecture 2 Outline 數 料 If if 狀 if 2 (Standard Output, stdout): 料. ((Standard Input, stdin): 料. 類 數 數 數 說 printf 見 數 puts 串 數 putchar

More information

C/C++基礎程式設計班

C/C++基礎程式設計班 C/C++ 基礎程式設計 指標 (Pointer) 講師 : 張傑帆 CSIE, NTU 瘋到自以為能改變世界的人, 就能改變世界 The people who are crazy enough to think they can change the world are the ones who do.-steve Jobs 課程大綱 指標簡介 陣列與指標 動態記憶體配置 指標宣告進階 指標 用途

More information

c_cpp

c_cpp C C++ C C++ C++ (object oriented) C C++.cpp C C++ C C++ : for (int i=0;i

More information

單步除錯 (1/10) 打開 Android Studio, 點選 Start a new Android Studio project 建立專案 Application name 輸入 BMI 點下 Next 2 P a g e

單步除錯 (1/10) 打開 Android Studio, 點選 Start a new Android Studio project 建立專案 Application name 輸入 BMI 點下 Next 2 P a g e Android Studio Debugging 本篇教學除了最基本的中斷點教學之外, 還有條件式中斷的教學 條件式中斷是進階的除錯技巧, 在某些特定情況中, 我們有一個函數可能會被呼叫數次, 但是我們只希望在某種條件成立時才進行中斷, 進而觀察變數的狀態 而條件式中斷這項技巧正是符合這項需求 本教學分兩部分 單步除錯 (Page2~11, 共 10) 條件式中斷點 (Page12~17, 共 6)

More information

Microsoft PowerPoint - C-Ch10.ppt

Microsoft PowerPoint - C-Ch10.ppt 了解陣列元素的位址 陣列 指標的應用 10-1 陣列與指標的關係 可以使用位址運算子 (&) 來查詢陣列中各個元素的位址 &test[0] 這行表示陣列最前面元素的位址 &test[1] 這行表示陣列第二個元素的位址 關於陣列名稱的機制 陣列名稱可以表示陣列最前面元素的位址 #include int main(void) int test[5] = 80,60,55,22,75;

More information

Generated by Unregistered Batch DOC TO PDF Converter , please register! 浙江大学 C 程序设计及实验 试题卷 学年春季学期考试时间 : 2003 年 6 月 20 日上午 8:3

Generated by Unregistered Batch DOC TO PDF Converter , please register! 浙江大学 C 程序设计及实验 试题卷 学年春季学期考试时间 : 2003 年 6 月 20 日上午 8:3 浙江大学 C 程序设计及实验 试题卷 2002-2003 学年春季学期考试时间 : 2003 年 6 月 20 日上午 8:30-10:30 注意 : 答题内容必须写在答题卷上, 写在本试题卷上无效 一. 单项选择题 ( 每题 1 分, 共 10 分 ) 1. 下列运算符中, 优先级最低的是 A.

More information

Microsoft Word - AEL 序-.doc

Microsoft Word - AEL 序-.doc 三版序 隨著電腦硬體技術不斷地進步, 軟體亦隨著日新月異 而指揮電腦運作的程式語言, 由早期的機器語言 組合語言 FORTRAN COBOL BASIC C PHP Java C++ 和 C# 等, 直不斷演進 其中 C 語言是 個 效率且介於 階和低階之語言, 適合開發各種系統或應用程式, 可攜性及執行效率, 因此很受程式設計師的喜愛, 尤其由 C 延伸出來的 C++ 是屬於物件導向程式語言, 很適合用來開發大型應用程式,

More information

untitled

untitled 1-1 1-2 1-3 1-4 1-5 1-6 1-7 1-8 1-1-1 C int main(void){ int x,y,z; int sum=0; double avg=0.0; scanf("%d",&x) ; scanf("%d",&y) ; scanf("%d",&z) ; sum=x+y+z ; avg=sum/3.0; printf("%f\n",avg); system("pause");

More information

CC213

CC213 : (Ken-Yi Lee), E-mail: feis.tw@gmail.com 49 [P.51] C/C++ [P.52] [P.53] [P.55] (int) [P.57] (float/double) [P.58] printf scanf [P.59] [P.61] ( / ) [P.62] (char) [P.65] : +-*/% [P.67] : = [P.68] : ,

More information

新版 明解C言語入門編

新版 明解C言語入門編 328, 4, 110, 189, 103, 11... 318. 274 6 ; 10 ; 5? 48 & & 228! 61!= 42 ^= 66 _ 82 /= 66 /* 3 / 19 ~ 164 OR 53 OR 164 = 66 ( ) 115 ( ) 31 ^ OR 164 [] 89, 241 [] 324 + + 4, 19, 241 + + 22 ++ 67 ++ 73 += 66

More information

新・明解C言語入門編『索引』

新・明解C言語入門編『索引』 !... 75!=... 48 "... 234 " "... 9, 84, 240 #define... 118, 213 #include... 148 %... 23 %... 23, 24 %%... 23 %d... 4 %f... 29 %ld... 177 %lf... 31 %lu... 177 %o... 196 %p... 262 %s... 242, 244 %u... 177

More information

C C

C C C C 2017 3 8 1. 2. 3. 4. char 5. 2/101 C 1. 3/101 C C = 5 (F 32). 9 F C 4/101 C 1 // fal2cel.c: Convert Fah temperature to Cel temperature 2 #include 3 int main(void) 4 { 5 float fah, cel; 6 printf("please

More information

C/C++ 语言 - 循环

C/C++ 语言 - 循环 C/C++ Table of contents 7. 1. 2. while 3. 4. 5. for 6. 8. (do while) 9. 10. (nested loop) 11. 12. 13. 1 // summing.c: # include int main ( void ) { long num ; long sum = 0L; int status ; printf

More information

C/C++基礎程式設計班

C/C++基礎程式設計班 C/C++ 基礎程式設計 字元與字串 講師 : 張傑帆 CSIE, NTU 人的出身並不重要, 你拿時間來做什麼才重要 It s not who you were at birth that matters, but what you do with the time you are given.-steve Jobs 課程大綱 字元 字串 作業 字元 在電腦的世界裡, 所有的一切都是以 0 與 1

More information

!153 第五講 函式 講師 : 李根逸 (Ken-Yi Lee),

!153 第五講 函式 講師 : 李根逸 (Ken-Yi Lee), 153 第五講 函式 講師 : 李根逸 (Ken-Yi Lee), E-mail: feis.tw@gmail.com 154 課程 大綱 函式宣告 [P.155] 函式呼叫 [P.156] C 標準函式庫 [P.157] 數學函式庫 [P.158] 函式定義 [P.160] 定義數學函式 [P.163] 定義模組化函式 [P.166] 變數可視範圍 [P.167] 在 for 的 小括號內宣告變數

More information

0 0 = 1 0 = 0 1 = = 1 1 = 0 0 = 1

0 0 = 1 0 = 0 1 = = 1 1 = 0 0 = 1 0 0 = 1 0 = 0 1 = 0 1 1 = 1 1 = 0 0 = 1 : = {0, 1} : 3 (,, ) = + (,, ) = + + (, ) = + (,,, ) = ( + )( + ) + ( + )( + ) + = + = = + + = + = ( + ) + = + ( + ) () = () ( + ) = + + = ( + )( + ) + = = + 0

More information

PowerPoint Presentation

PowerPoint Presentation 語法復習 NTU CSIE 張傑帆 整合開發環境 NTU CSIE 張傑帆 C++ 開發工具 整合式開發環境 (Integrated Development Environment) 簡稱 IDE 是整合編輯 編譯 測試 除錯 與執行等功能的程式開發軟體 例如 Borland 公司的 C++ Builder IBM 公司的 VisualAge C++ Microsoft 公司的 Visual C++

More information

C/C++语言 - C/C++数据

C/C++语言 - C/C++数据 C/C++ C/C++ Table of contents 1. 2. 3. 4. char 5. 1 C = 5 (F 32). 9 F C 2 1 // fal2cel. c: Convert Fah temperature to Cel temperature 2 # include < stdio.h> 3 int main ( void ) 4 { 5 float fah, cel ;

More information

2015年计算机二级(C语言)模拟试题及答案(四)

2015年计算机二级(C语言)模拟试题及答案(四) 2016 年 计 算 机 二 级 (C 语 言 ) 模 拟 试 题 及 答 案 (4) 一 填 空 题 1 C 语 言 中 基 本 的 数 据 类 型 有 : 2 C 语 言 中 普 通 整 型 变 量 的 类 型 说 明 符 为, 在 内 存 中 占 字 节, 有 符 号 普 通 整 型 的 数 据 范 围 是 3 整 数 -35 在 机 内 的 补 码 表 示 为 4 执 行 下 列 语 句 int

More information

untitled

untitled 1 DBF (READDBF.C)... 1 2 (filetest.c)...2 3 (mousetes.c)...3 4 (painttes.c)...5 5 (dirtest.c)...9 6 (list.c)...9 1 dbf (readdbf.c) /* dbf */ #include int rf,k,reclen,addr,*p1; long brec,erec,i,j,recnum,*p2;

More information

C/C++程序设计 - 字符串与格式化输入/输出

C/C++程序设计 - 字符串与格式化输入/输出 C/C++ / Table of contents 1. 2. 3. 4. 1 i # include # include // density of human body : 1. 04 e3 kg / m ^3 # define DENSITY 1. 04 e3 int main ( void ) { float weight, volume ; int

More information

Microsoft PowerPoint - Class5.pptx

Microsoft PowerPoint - Class5.pptx C++ 程式初探 V 2015 暑期 ver. 1.0.1 C++ 程式語言 大綱 1. 大量檔案讀取 & 計算 2. 指標 3. 動態記憶體 & 動態陣列 4. 標準函式庫 (STL) vector, algorithm 5. 結構與類別 2 大量檔案讀取 & 計算 若目前有一個程式將讀取純文字文件 (.txt) 中的整數, 並將該文件中的整數有小到大排序後, 儲存到另外一個新的純文字件中 假設有

More information

C

C C 2017 4 1 1. 2. while 3. 4. 5. for 6. 2/161 C 7. 8. (do while) 9. 10. (nested loop) 11. 12. 3/161 C 1. I 1 // summing.c: 2 #include 3 int main(void) 4 { 5 long num; 6 long sum = 0L; 7 int status;

More information

第1章

第1章 第 8 章 函式 1 本章提要 8.1 前言 8.2 如何定義函式 8.3 函式的呼叫和返回 8.4 傳遞陣列 8.5 方法多載 8.6 遞迴 8.7 綜合練習 8.8 後記 2 8.1 前言 每一種高階程式語言都有提供函式 (Function)( 或稱函數 ) 的功能, 以便將經常使用到的程式功能包裝成函式的形式, 如此一來便能反覆地呼叫該函式來完成某件特定工作在高階程式語言中, 副程式 (Subroutine)

More information

壹、課程說明

壹、課程說明 壹 課程說明單元名稱進階程式設計 使用 C 語言 ( 選修一學分 ) 3-2 1. 陣列與字串 2. 函式與巨集 ( 本教案設計部份 : 課程規劃時數 6 節 ) 單元摘要 3. 指標 4. 變數等級 5. 檔案處理設計者林光耀老師 ( 國立鳳新高級中學 ) 1. 能說明陣列與字串的功能, 及在程式設計中的使用時機 2. 能說明函式與巨集的功能, 及在程式設計中的使用時機 學習目標課綱範圍教學節數先備知識評量方法

More information

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2

Python a p p l e b e a r c Fruit Animal a p p l e b e a r c 2-2 Chapter 02 變數與運算式 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.2 2.2.1 2.2.2 2.2.3 type 2.2.4 2.3 2.3.1 print 2.3.2 input 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 + 2.4.6 Python Python 2.1 2.1.1 a p p l e b e a r c 65438790

More information

C

C C 2017 3 14 1. 2. 3. 4. 2/95 C 1. 3/95 C I 1 // talkback.c: 2 #include 3 #include 4 #define DENSITY 62.4 5 int main(void) 6 { 7 float weight, volume; 8 int size; 9 unsigned long letters;

More information

碩命題橫式

碩命題橫式 一 解釋名詞 :(50%) 1. Two s complement of an integer in binary 2. Arithmetic right shift of a signed integer 3. Pipelining in instruction execution 4. Highest and lowest layers in the TCP/IP protocol suite

More information

Microsoft Word - 2CA13內文.doc

Microsoft Word - 2CA13內文.doc 006 公 民 - 歷 屆 試 題 全 解 答 案 是 完 全 正 確 的? : 能 源 使 用 愈 多, 除 了 帶 來 經 濟 成 長 外, 相 對 的, 也 會 帶 來 負 面 的 環 保 問 題 我 們 在 發 展 經 濟 的 過 程 中, 若 不 能 兼 顧 環 境 資 源 的 保 育, 將 賠 上 後 代 子 孫 的 生 存 環 境, 這 是 下 列 那 一 種 理 念? 比 較 利 益

More information

The golden pins of the PCI card can be oxidized after months or years

The golden pins of the PCI card can be oxidized after months or years Q. 如何在 LabWindows/CVI 編譯 DAQ Card 程式? A: 請參考至下列步驟 : 步驟 1: 安裝驅動程式 1. 安裝 UniDAQ 驅動程式 UniDAQ 驅動程式下載位置 : CD:\NAPDOS\PCI\UniDAQ\DLL\Driver\ ftp://ftp.icpdas.com/pub/cd/iocard/pci/napdos/pci/unidaq/dll/driver/

More information

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023) ( CIP) /. :, 2005. 2 ( ) ISBN 7-5624-3339-9.......... TP311. 1 CIP ( 2005) 011794 : : : : * : : 174 ( A ) :400030 : ( 023) 65102378 65105781 : ( 023) 65103686 65105565 : http: / /www. cqup. com. cn : fxk@cqup.

More information

C/C++ - 字符串与字符串函数

C/C++ - 字符串与字符串函数 C/C++ Table of contents 1. 2. 3. 4. 1 char C 2 char greeting [50] = " How " " are " " you?"; char greeting [50] = " How are you?"; 3 printf ("\" Ready, go!\" exclaimed John."); " Ready, go!" exclaimed

More information

untitled

untitled 串 串 例 : char ch= a ; char str[]= Hello ; 串 列 ch=getchar(); scanf( %c,&ch); 串 gets(str) scanf( %s,str); 8-1 數 ASCII 例 : char ch= A ; printf( %d,ch); // 65 A ascii =0x41 printf( %c,ch); // A 例 : char ch;

More information

Microsoft PowerPoint - Bronson-v3-ch06.ppt [相容模式]

Microsoft PowerPoint - Bronson-v3-ch06.ppt [相容模式] C++ FOR ENGINEERS AND SCIENTISTS THIRD EDITION Chapter 6 Modularity Using Functions Objectives 2 In this chapter, you will learn about: Function and parameter declarations 函數和參數宣告 Returning a single value

More information

C/C++基礎程式設計班

C/C++基礎程式設計班 C/C++ 基礎程式設計 字元與字串 講師 : 張傑帆 CSIE, NTU 人的出身並不重要, 你拿時間來做什麼才重要 It s not who you were at birth that matters, but what you do with the time you are given.-steve Jobs 課程大綱 字元 字串 作業 字元 在電腦的世界裡, 所有的一切都是以 0 與 1

More information

Excel VBA Excel Visual Basic for Application

Excel VBA  Excel Visual Basic for Application Excel VBA Jun5,00 Sub 分頁 () Dim i As Integer Dim Cname As String Dim Code As Variant Set score=thisworkbook.sheets("sheet") Code=Array(" 專北一 "," 專北二 "," 專北三 "," 專桃園 "," 專桃竹 "," 專中苗 ", " 專台中 "," 專台南 ","

More information

Microsoft PowerPoint - STU_C_Lang_CH13.ppt

Microsoft PowerPoint - STU_C_Lang_CH13.ppt 第 13 章 動態配置記憶體 程式設計與生活 - 使用 C 語言 Shi-Huang Chen Spring 2013 第 13 章 動態配置記憶體 13-1 記憶體配置函式 malloc( ) 13-2 動態配置結構陣列 配置記憶體 預估需求數量的範圍是一項不容易的學問 例 : 大到預估今年國家預算, 小到預估櫥窗裡展示的毛線衣, 需要多少磅毛線才能織成 撰寫程式時, 一樣無法預估程式執行所需的記憶體空間

More information

新・解きながら学ぶC言語

新・解きながら学ぶC言語 330!... 67!=... 42 "... 215 " "... 6, 77, 222 #define... 114, 194 #include... 145 %... 21 %... 21 %%... 21 %f... 26 %ld... 162 %lf... 26 %lu... 162 %o... 180 %p... 248 %s... 223, 224 %u... 162 %x... 180

More information

投影片 1

投影片 1 資料庫管理程式 ( 補充教材 -Part2) 使用 ADO.NET 連結資料庫 ( 自行撰寫程式碼 以實現新增 刪除 修改等功能 ) Private Sub InsertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertButton.Click ' 宣告相關的 Connection

More information

C/C++ - 数组与指针

C/C++ - 数组与指针 C/C++ Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1 float candy [ 365]; char code [12]; int states [50]; 2 int array [6] = {1, 2, 4, 6, 8, 10}; 3 // day_mon1.c: # include # define MONTHS 12 int

More information

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien

Scott Effective C++ C++ C++ Roger Orr OR/2 ISO C++ Effective Modern C++ C++ C++ Scoot 42 Bart Vandewoestyne C++ C++ Scott Effective Modern C++ Damien Effective Modern C++ C++ C++ C++11/C++14 C++ Scott Meyers Gerhard Kreuzer Siemens AG Effective Modern C++ Effective Modern C++ Andrei Alexandrescu Facebook Modern C++ Design C++ C++ Nevin Liber DRW Trading

More information

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc References (Section 5.2) Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 15-16, 2010 H.-T. Lin (NTU CSIE) References OOP 03/15-16/2010 0 / 22 Fun Time (1) What happens in memory? 1 i n t i ; 2

More information

untitled

untitled CHAPTER 02 2 CHAPTER 2-1 2-4 2-2 2-5 2-3 2-6 2-1 2-1-1 2-2 02 int A[3] = {10, 20, 30; A[0] 10 A[1] 20 A[2] 30 int *pa[3], A[3]; C 3 pa pa[0]pa[1]pa[2] 3 A A[0]A[1]A[2] 3 A A[0] A + i A[i] A + i &A[i]*(A

More information

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf(%d, &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf(% 2013 ( 28 ) ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 10 B 1 C 1 D 5 E 5 F 1 G II 5 H 30 1 2013 C 1 #include 2 int main(void) 3

More information

105A 資管一程式設計實驗 06 函式定義謝明哲老師 2 程式設計實驗 6.3: 自行定義一個可以接受兩個整數並傳回其最大公因數的函式, 接著利用該函式自 行定義一個可以接受兩個整數並傳回其最小公倍數函式 // gcd_fcn.cpp int gcd(int m,

105A 資管一程式設計實驗 06 函式定義謝明哲老師 2 程式設計實驗 6.3: 自行定義一個可以接受兩個整數並傳回其最大公因數的函式, 接著利用該函式自 行定義一個可以接受兩個整數並傳回其最小公倍數函式 // gcd_fcn.cpp int gcd(int m, 105A 資管一程式設計實驗 06 函式定義謝明哲老師 hmz@nttu.edu.tw 1 程式設計實驗 06 函式定義 模擬問題 03 在模擬問題 02, 小組已完成擬定一個與學習或日常生活有關的問題, 並依據在 Ch5 所 學到的流程控制與檔案存取技術發展小組的第二版個別化資訊服務程式 現在請小組對第二版程式的 結構進行分析, 檢查是否有哪些功能可以使用在 Ch6 所學到的函式定義來加以模組化,

More information

Microsoft Word C-A卷.docx

Microsoft Word C-A卷.docx 100 學年度資訊學院程式設計會考 (C) 101/05/5 題組 :A 選擇題及填充題, 請在答案卡上作答, 實作題請填寫於答案卷上, 並於實作題上方填寫班級 姓名 學號 一 選擇題題目 1. unsigned char 的最大值 (a) 127 (b) 255 (c) 512 (d) 1023 2. 下列何者為正確的變數名稱? (a) Android (b) C++ (c) I Phone (d)

More information

华恒家庭网关方案

华恒家庭网关方案 LINUX V1.5 1 2 1 2 LINUX WINDOWS PC VC LINUX WINDOWS LINUX 90% GUI LINUX C 3 REDHAT 9 LINUX PC TFTP/NFS http://www.hhcn.com/chinese/embedlinux-res.html minicom NFS mount C HHARM9-EDU 1 LINUX HHARM9-EDU

More information

untitled

untitled 不 料 料 例 : ( 料 ) 串 度 8 年 數 串 度 4 串 度 數 數 9- ( ) 利 數 struct { ; ; 數 struct 數 ; 9-2 數 利 數 C struct 數 ; C++ 數 ; struct 省略 9-3 例 ( 料 例 ) struct people{ char name[]; int age; char address[4]; char phone[]; int

More information

Microsoft Word - ch10.doc

Microsoft Word - ch10.doc CHAPTER 10 變數的儲存類別 10.1 變數的儲存類別 10.2 自動變數 10.3 靜態變數 10.4 外部變數 10.5 暫存器變數 10.6 習題 10.1 變數的儲存類別 在第三章當您宣告一個變數時, 便可得知變數的名稱 變數是屬於哪種資料型別 該變數佔用記憶體有多少個 Bytes 當設計較大程式時, 使用的變數一多, 就必須考慮變數在記憶體中的配置情形 本章主要探討變數的儲存類別

More information

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp

Spyder Anaconda Spyder Python Spyder Python Spyder Spyder Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Sp 01 1.6 Spyder Anaconda Spyder Python Spyder Python Spyder Spyder 1.6.1 Spyder 開始 \ 所有程式 \ Anaconda3 (64-bit) \ Spyder Spyder IPython Python IPython Spyder Python File

More information

Microsoft Word - Prog1-981.docx

Microsoft Word - Prog1-981.docx 5. 變數參照 (Memory Reference) 5.1 指標 (Pointer) (1). 指標 (Pointer) 的基本觀念 特性 內含為一 Memory Address 會因不同的機器而有不同的結果 &" 也是代表變數的位址 例如 : int var1 = 2; cout

More information

用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應

用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應 專題進度 老師 : 趙啟時老師 學生 : 陳建廷 2013/10/13 用手機直接傳值不透過網頁連接, 來當作搖控器控制家電 ( 電視遙控器 ) 按下按鍵發送同時會回傳值來確定是否有送出 問題 :1. 應該是使用了太多 thread 導致在傳值上有問題 2. 一次按很多次按鈕沒辦法即時反應 程式碼 : package com.example.phone; import java.util.arraylist;

More information

[改訂新版]C言語による標準アルゴリズム事典

[改訂新版]C言語による標準アルゴリズム事典 iii C 1991 SEND + MORE = MONEY C 100 2003 Java 2003 27 PC-9800 C BMP SVG EPS BMPSVG WindowsMacLinux Web iv int main() int main(void) EXIT_SUCCESS 0 https://github.com/okumuralab/ algo-c TEX TEX PDF PDF

More information

C++

C++ 第五講 泛型程式設計 講師 : 李根逸 (Ken-Yi Lee), E-mail: feis.tw@gmail.com 130 課程 大綱 模版 (template) 簡介實作多個相似內容的函式函式模版類別模版 自製陣列模版 static 的 用法修飾全域變數或 一般函式修飾區域變數修飾類別成員 C++ STL 的陣列模版 (std::vector) 131 實作多個相似內容的函式 [1] 寫 C/C++

More information

The return of scanf The number of fields successfully converted and assigned int a =1, b =2, c =3; int n = scanf("%d %d %d", &a, &b, &c); printf("%d\n

The return of scanf The number of fields successfully converted and assigned int a =1, b =2, c =3; int n = scanf(%d %d %d, &a, &b, &c); printf(%d\n Introduction to Computer and Program Design Lesson 2 Functions, scanf and EOF James C.C. Cheng Department of Computer Science National Chiao Tung University The return of scanf The number of fields successfully

More information

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf (%d, & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf (%d %d 2013 18 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp, Compilation Error cin scanf Time Limit Exceeded 1: A 5 B 5 C 5 D 5 E 5 F 5 1 2013 C 1 # include 2 int main ( void ) 3 { 4 int cases, a, b,

More information

Microsoft Word - 投影片ch06

Microsoft Word - 投影片ch06 Java2 JDK5.0 教學手冊第三版洪維恩編著博碩文化出版書號 pg20210 第六章陣列 本章學習目標認識陣列與一般資料型態的不同認識一維與二維陣列學習陣列的應用 陣列 6-2 6.1 一維陣列 一維陣列 (1-dimensional array) 可以存放多個相同資料型態的資料 6.1.1 一維陣列的宣告與記憶體的配置 要使用陣列必須經過兩個步驟 :(1) 宣告陣列 (2) 配置記憶體給該陣列

More information

C/C++ - 字符输入输出和字符确认

C/C++ - 字符输入输出和字符确认 C/C++ Table of contents 1. 2. getchar() putchar() 3. (Buffer) 4. 5. 6. 7. 8. 1 2 3 1 // pseudo code 2 read a character 3 while there is more input 4 increment character count 5 if a line has been read,

More information

C 1

C 1 C homepage: xpzhangme 2018 5 30 C 1 C min(x, y) double C // min c # include # include double min ( double x, double y); int main ( int argc, char * argv []) { double x, y; if( argc!=

More information

C/C++基礎程式設計班

C/C++基礎程式設計班 C/C++ 基礎程式設計 C++: 物件的使用 參考 重載函式 成就別人認為不可能的事 Do what nobody else considered possible. -Steve Jobs 講師 : 張傑帆 CSIE NTU C++ 相較於 C 的特色 向下相容 在 C 語言中, 我們學了許多程式語法, 所有學過的東西, 在 C++ 中都可以使用 高階的程式描述方式 更利於用來開發大型專案, 讓程式設計師在分工時更能快速的開發程式,

More information

プログラムの設計と実現II

プログラムの設計と実現II UNIX C ls mkdir man http://www.tj.chiba-u.jp/lecture/prog2/ Ctrl+x, Ctrl+s ( )..[4]% gcc Wall o hoge hoge.c..[5]%./hoge 1 : 1 2 : 2 3 : 3 4 : 0 6..[6]% (! )..[4]% gcc Wall o hoge hoge.c..[5]%!g gcc Wall

More information

WWW PHP

WWW PHP WWW PHP 2003 1 2 function function_name (parameter 1, parameter 2, parameter n ) statement list function_name sin, Sin, SIN parameter 1, parameter 2, parameter n 0 1 1 PHP HTML 3 function strcat ($left,

More information

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf (%d, & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9 201 201 21 ( ) 1. C pa.c, pb.c, 2. C++ pa.cpp, pb.cpp Compilation Error long long cin scanf Time Limit Exceeded 1: A 1 B 1 C 5 D RPG 10 E 10 F 1 G II 1 1 201 201 C 1 # include 2 int main ( void

More information

epub 33-8

epub 33-8 8 1) 2) 3) A S C I I 4 C I / O I / 8.1 8.1.1 1. ANSI C F I L E s t d i o. h typedef struct i n t _ f d ; i n t _ c l e f t ; i n t _ m o d e ; c h a r *_ n e x t ; char *_buff; /* /* /* /* /* 1 5 4 C FILE

More information

C 語言—陣列及字串

C 語言—陣列及字串 10/16 系程主講人 : 荊輔翔 概論 陣列 陣列是一個具有索引 (index) 性質的連續資料儲存空間集合 陣列中每一個資料儲存空間稱之為陣列元素 (array element); 它們都具有相同的資料名稱 資料型態 及空間大小 ; 但存取它們時則須藉由索引 ( 或稱註標 ) 來區別辨識 索引代表資料在陣列中的相對位址 ( 其計數由 0 開始, 其餘累加類推 ), 且須由中括號 [ ] 涵蓋之

More information

_汪_文前新ok[3.1].doc

_汪_文前新ok[3.1].doc 普 通 高 校 本 科 计 算 机 专 业 特 色 教 材 精 选 四 川 大 学 计 算 机 学 院 国 家 示 范 性 软 件 学 院 精 品 课 程 基 金 青 年 基 金 资 助 项 目 C 语 言 程 序 设 计 (C99 版 ) 陈 良 银 游 洪 跃 李 旭 伟 主 编 李 志 蜀 唐 宁 九 李 涛 主 审 清 华 大 学 出 版 社 北 京 i 内 容 简 介 本 教 材 面 向

More information

踏出C++的第一步

踏出C++的第一步 踏出 C++ 的第一步 講師 : 洪安 1 已經學會的 C 語言基本概念 基本資料型態 變數 基本輸入輸出 控制敘述 選擇控制 迴圈 陣列 函式 指標 字元與字串 結構 檔案處理 2 C v.s. C++ C 函數 程序式語言 Procedural language 結構化程式設計 Structured programming 演算法 Top-down C++ 類別 物件導向程式設計 Object-Oriented

More information

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc 2 5 8 11 0 1. 13 2. 15 3. 18 1 1. 22 2. 25 3. 27 2 1. 35 2. 38 3. 41 4. 43 5. 48 6. 50 3 1. 56 2. 59 3. 63 4. 65 5. 69 13 22 35 56 6. 74 7. 82 8. 84 9. 87 10. 97 11. 102 12. 107 13. 111 4 114 1. 114 2.

More information

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit 6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C51 6.1 C51 6.1.1 C51 C51 ANSI C MCS-51 C51 ANSI C C51 6.1 6.1 C51 bit Byte bit sbit 1 0 1 unsigned char 8 1 0 255 Signed char 8 11 128

More information

投稿類別:資訊類

投稿類別:資訊類 投稿類別 : 資訊類 篇名 : 從 VB.Net 學 C# 作者 : 陳諭瑩 高雄市立高雄高級工業職業學校 資訊科高三乙班王子喬 高雄市立高雄高級工業職業學校 資訊科高三乙班李宗恩 高雄市立高雄高級工業職業學校 資訊科高三乙班 指導老師 : 莊利吉老師 壹 前言 一 研究動機 在高職裡 VB.Net 是課程標準, 但由於現在職場上大部分都是使用 C#, 所以我們用 VB.Net 的基礎學 C#, 再利用高職所學到的

More information

105Tr_CIS1

105Tr_CIS1 准考證號碼 : 國立臺中教育大學 105 學年度學士班日間部轉學招生考試 計算機概論試題 適用學系 : 資訊工程學系二 三年級 一 選擇題 (40%, 每題 2%) 1. 在物件導向程式設計中, 一個抽象類別 (Abstract Class) 為 A. 一個沒有方法 (method) 的類別 B. 一個不能被繼承 (inherit) 的類別 C. 一個不能被實體化 (instantiated) 的類別

More information

Microsoft Word - 2008年9月二级C真卷.doc

Microsoft Word - 2008年9月二级C真卷.doc 机 密 启 用 前 2008 年 9 月 全 国 计 算 机 等 级 考 试 二 级 笔 试 试 卷 C 语 言 程 序 设 计 24 注 意 事 项 一 考 生 应 严 格 遵 守 考 场 规 则, 得 到 监 考 人 员 指 令 后 方 可 作 答 二 考 生 拿 到 试 卷 后 应 首 先 将 自 己 的 姓 名 准 考 证 号 等 内 容 涂 写 在 答 题 卡 的 相 应 位 置 上 三

More information

extend

extend (object oriented) Encapsulation Inheritance Polymorphism Dynamic Binding (base class) (derived class) 1 class Base { int I; void X(); void Y(); class Derived: public Base { private: int j; void z(); Derived

More information

Microsoft Word - 投影片ch11

Microsoft Word - 投影片ch11 Java2 JDK5.0 教學手冊第三版洪維恩編著博碩文化出版書號 pg20210 第十一章抽象類別與介面 本章學習目標認識抽象類別學習介面的使用認識多重繼承與介面的延伸 抽象類別與介面 11-2 11.1 抽象類別 抽象類別的目的是要依據它的格式來修改並建立新的類別 11.1.1 定義抽象類別 定義抽象類別的語法如下 : abstract class 類別名稱 { 宣告資料成員 ; // 定義抽象類別

More information

Ps22Pdf

Ps22Pdf ( 98 ) C ( ) ( )158 1998 C : C C C,,, C,, : C ( ) : : (, 100084) : : : 7871092 1/ 16 :18 25 :415 : 2000 3 1 2000 3 1 : ISBN 7 302 01166 4/ T P432 : 00016000 : 22 00 ( 98 ) 20 90,,, ;,,, 1994, 1998, 160,

More information

第二章 簡介類別

第二章  簡介類別 Instructor 曾學文 hwtseng@nchu.edu.tw http://wccclab.cs.nchu.edu.tw/www/index.php/c ourse/2017-03-20-07-38-21/105-105-2-c TA 王昱彬 第一章概觀 C++ 1-2 二種版本的 C++ 1-5 初步檢視類別 1-1 何謂物件導向程式設計 1-8 C++ 的關鍵字 1-2 二種版本的 C++

More information

C/C++基礎程式設計班

C/C++基礎程式設計班 C/C++ 基礎程式設計 流程控制敘述 講師 : 張傑帆 CSIE, NTU 追隨我的好奇與直覺, 大部分我所投入過的事務, 後來都成了無比珍貴的經歷 Much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. -Steve Jobs 課程大綱 選擇控制

More information