12.07.2015 Views

PDF檔講義

PDF檔講義

PDF檔講義

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

期 中 考P.C. Lin


USAID-RWANDA-RFA-696-11-000003Government. Issuance of this RFA does not constitute an award commitment on the part of theGovernment nor does it commit the Government to pay for costs incurred in the preparation andsubmission of an application. In addition, final award of any resultant cooperative agreement(s) cannotbe made until funds have been fully appropriated, allocated and committed through internal USAIDprocedures. While it is anticipated that these procedures will be successfully completed, potentialapplicants are hereby notified of these requirements and conditions for award. Applications aresubmitted at the risk of the applicant. Should circumstances prevent USAID from making an award, allpreparation and submission costs are at the applicant’s expense.For the purposes of this RFA, the term "Grant" is synonymous with "Cooperative Agreement"; "Grantee"is synonymous with "Recipient"; and "Grant Officer" is synonymous with "Agreement Officer".This RFA and any future amendments to it can be downloaded from http://www.grants.gov. Select “FindGrant Opportunities” then click on “Browse by Agency”, and select the “U.S. Agency for InternationalDevelopment” and search for the RFA. In the event of an inconsistency between the documentscomprising this RFA, it shall be resolved at the discretion of the Agreement Officer.Any clarification questions concerning this RFA should be submitted in writing to Camille Garcia, theRegional Agreement Officer, via e-mail at cgarcia@usaid.gov with a copy Geraldine Kyazze, Sr.Acquisition and Assistance Specialist at gkyazze@usaid.gov by the date and time listed at the top on thiscover letter.Electronic submission of applications is required. The Applicant must submit the application in twoseparate parts: (a) technical, and (b) cost or business application to Camille Garcia, the RegionalAgreement Officer via e-mail at cgarcia@usaid.gov with a copy Geraldine Kyazze, Sr. Acquisition andAssistance Specialist at gkyazze@usaid.gov.The Applicant must submit an application by the closing date and time listed at the top of this coverletter. Applications must be directly responsive to the terms and conditions of this RFA. Telegraphic orfax applications are not authorized for this RFA and will not be accepted.To be eligible for award, the applicant must provide all required information in its application, includingall the requirements found in any attachments to this RFA.Sincerely,//signed//Camille GarciaRegional Agreement OfficerUSAID/EAST AFRICA2


期 中 考 複 習各 教 學 進 度 題 庫 中 的 題 目 請 同 學 自 行 練 習P.C. Lin


認 識 C 語 言• C 語 言 為 一 種 高 階 的 編 譯 式 程 式 語 言 , 程 式 語 言屬 於 系 統 軟 體 ; 撰 寫 C 語 言 程 式 時 , 先 在 編 輯 軟體 中 完 成 C 的 原 始 程 式 ( 副 檔 名 .c) 後 , 將 原 始 程式 編 譯 成 目 的 程 式 ( 副 檔 名 .exe) , 目 的 程 式 是 電腦 看 得 懂 的 執 行 檔 , 執 行 目 的 程 式 , 電 腦 就 會依 我 們 所 下 的 指 令 去 完 成 工 作 。• 例 如 : 利 用 DEV C++ 編 輯 C 語 言 程 式 hello.c 後 ,利 用 DEV C++ 軟 體 的 GCC 編 譯 器 將 語 法 無 誤 的hello.c 編 譯 產 生 hello.exe 執 行 檔 ( 目 的 程 式 ) 後 ,執 行 hello.exe 測 試 是 否 符 合 需 求 。


C 程 式 的 步 驟1. 編 輯 : 使 用 編 輯 器 編 輯 C 語 言 的 原 始 程 式 。2. 編 譯 : 使 用 C 語 言 的 編 譯 器 gcc 或 tcc , 將 C語 言 的 原 始 程 式 (*.c) 在 語 法 無 誤 的 情 形 下 ,編 譯 出 一 個 執 行 程 式 (*.exe); 如 果 語 法 有誤 , 則 需 回 到 第 1 個 步 驟 重 新 修 改 C 語 言 的原 始 程 式 。3. 執 行 : 利 用 整 合 環 境 或 命 令 提 示 字 元 , 執行 .exe 檔 , 測 試 程 式 是 否 符 合 需 求 。


C 語 言 的 元 素1. 字 元 集 : 英 文 字 母 、 數 字 、 特 殊 字 元 、 逸出 字 元 及 運 算 子2. 常 數 : 整 數 常 數 、 浮 點 常 數 、 字 串 常 數 及列 舉 常 數3. 識 別 字 : 由 字 母 、 數 字 與 底 線 所 構 成 的 非關 鍵 字4. 關 鍵 字 : C 語 言 已 經 有 定 義 的 保 留 字5. 註 解 : /* 與 */ 之 間 的 文 字 , 視 為 空 白 字 元


前 置 處 理• 在 撰 寫 C 語 言 程 式 之 前 , 要 做 的 事 就 是 前 置 處 理 ,例 如 : 如 果 要 利 用 stdio.h 中 的 printf() 函 式 和 scanf()函 式 , 就 要 先 在 前 置 處 理 中 先 匯 入 stdio.h 檔 。• 種 類 :1. 匯 入 系 統 .h 表 頭 檔 - #include < 檔 名 >例 如 : #include 2. 匯 入 自 行 撰 寫 表 頭 檔 - #include “ 檔 名 ”例 如 : #include “mylib.h”3. 定 義 符 號 常 數 - #define 符 號 常 數 名 值例 如 : #define PI 3.14


C 槽 系 統 include 目 錄 中 的 表 頭 檔


main() 函 式 與 註 解• main( ) 函 式 是 C 語 言 指 定 的 執 行 函 式 , 如 果 您 的程 式 需 要 能 執 行 , 則 要 執 行 的 指 令 、 敘 述 或 函式 就 必 需 寫 在 main( ) 函 式 中 。• 宣 告 main 函 式int main (void){宣 告 ;敘 述 ;}複 合 敘 述 中 的宣 告 和 敘 述 都要 以 分 號 ; 結 束• 程 式 中 的 註 解 以 /* 開 始 , 以 */ 結 束 。


變 數 的 宣 告• 也 就 是 告 訴 電 腦 你 將 要 使 用 的 記 憶 體 空 間 有 哪些 ! 換 句 話 說 , 也 就 是 程 式 設 計 者 計 劃 要 儲 存 ( 使用 者 輸 入 、 計 算 或 判 斷 的 結 果 )、 處 理 ( 計 算 或 判斷 ) 的 資 料 要 利 用 的 記 憶 體 空 間 。• 宣 告 變 數 要 注 意 :1. 變 數 的 種 類 - 常 用 的 有 int( 整 數 ) 、 float( 浮 點 數 ) 、char( 字 元 )2. 變 數 宣 告 的 格 式 - 型 態 變 數 名 ;3. 變 數 的 初 始 化 ( 記 憶 體 空 間 要 有 值 才 能 被 處 理 )-(a) 指 定 敘 述 , 例 如 : int a = 0 ;(b) 儲 存 scanf 函 式 所 取 得 的 輸 入 資 料 , 例 如 :int b; scanf(“%d”, &b);


變 數 範 例• 宣 告 2 個 整 數 變 數 a 和 b, 令 b 的 初 值 為 0。int a, b; b=0; 或 int a, b=0;( 宣 告 同 一 型 態 的 變 數 可 以 逗 點 分 隔 )• 宣 告 2 個 字 元 變 數 myc 和 myd, 令 myd 初 值 為 D 。char myc, myd; myd=‘D’; 或 char myc, myd=‘D’;(C 語 言 的 字 元 值 要 以 單 引 號 ‘’ 做 識 別 , 字 串 值 則以 雙 引 號 “” 做 為 識 別 )• 宣 告 2 個 浮 點 變 數 fx 和 fy, 令 fx 的 初 值 為 1.23 。float fx, fy; fx=1.23; 或 float fx, fy=1.23;


C 語 言 的 敘 述指 定 敘 述輸 出 入 函 式選 擇 流 程 控 制


指 定 敘 述• 指 定 敘 述 利 用 指 定 運 算 子 = 將 右 方 常 數 、 運 算式 或 函 式 回 傳 的 值 指 定 存 放 至 等 號 左 方 變 數 的記 憶 體 位 置 中 。 例 如 :1. 宣 告 一 個 字 元 變 數 其 值 為 A 。 char mytype=‘A’;2. float fa, fb=1.23, fc=2.34; 將 fb 和 fc 的 和 指 定 給 fa 。fa = fb+fc;3. int a=5, b, c=2; 將 a 除 以 c 的 值 指 定 給 b 。b = a/c;4. int m, n=7; 將 n 除 以 2 的 餘 數 指 定 給 m 。m = n%2;


scanf() 輸 入 函 式• 在 C 語 言 程 式 中 , 我 們 經 常 要 利 用 輸 入 函 式scanf() 及 輸 出 函 式 printf()。 例 如 :1. 請 寫 出 一 個 輸 入 函 式 , 將 輸 入 的 整 數 儲 存 到 變數 a 中 。int a ; scanf(“%d”, &a);2. 請 寫 出 一 個 輸 入 函 式 , 將 輸 入 的 浮 點 數 儲 存 到變 數 b 中 。float b ; scanf(“%f”, &b);3. 請 寫 出 一 個 輸 入 函 式 , 將 輸 入 的 字 元 儲 存 到 變數 myc 中 。char myc ; scanf(“%c”, &myc);


printf() 輸 出 函 式1. 請 寫 出 一 個 輸 出 函 式 , 將 “ 期 末 考 ” 三 個 字輸 出 至 螢 幕 。printf(“ 期 末 考 ”);2. 請 寫 出 一 個 輸 出 函 式 , 將 整 數 變 數 a 的 值 輸出 至 螢 幕 。printf(“%d”, a);3. 請 寫 出 一 個 輸 出 函 式 , 將 字 元 變 數 myc 的 值輸 出 至 螢 幕 第 二 列 。printf(“\n%c”, myc);


C 語 言 的 流 程 控 制• 在 正 常 的 情 形 下 , 程 式 的 敍 述 是 一 個 接 一個 , 依 序 被 執 行 的 ! 所 以 程 式 碼 撰 寫 的 順 序直 接 影 響 到 執 行 的 結 果 , 稱 為 循 序 流 程 。• 當 有 需 要 條 件 判 斷 時 , 需 用 到 選 擇 流程 控 制 。(if 敘 述 、 switch 敘 述 )• 當 部 份 程 式 在 特 定 條 件 下 需 要 重 覆 執行 時 , 需 要 用 到 重 覆 流 程 控 制 。(while敘 述 、 do/while 敘 述 及 for 敘 述 )


影 響 流 程 控 制 的 運 算 子• 影 響 程 式 執 行 流 程 的 控 制 運 算 子 有 :– 關 係 運 算 子 :< 小 於 、> 大 於 、= 大 於 等 於– 相 等 運 算 子 : == 相 等 、!= 不 相 等– 邏 輯 運 算 子 :! 相 反 、 不 、not&& 及 、 而 且 、and|| 或 、or


選 擇 流 程 控 制• 一 般 的 程 式 是 會 用 到 判 斷 所 需 的 條 件 運 算式 (condition expression), 簡 稱 條 件 式 。依 據 條 件 式 值 的 真 (true) 或 假 (false) 來判 斷 要 執 行 那 一 區 塊 (block) 的 程 式 碼 。•ANSI C 並 沒 有 boolean 資 料 型 態 , 也 就 是說 true 及 false 這 兩 個 識 別 字 ANSI C 並 沒 有定 義 , 通 常 以 整 數 1( 非 0) 表 示 真 , 以 整數 0 表 示 假 。


if 敘 述•if ( 判 斷 條 件 ){ 判 斷 條 件 為 真 時 所執 行 的 複 合 敘 述 ; }•if 敘 述 , 只 要 括 號 中 的條 件 值 為 true, 就 執 行其 後 的 敘 述 , 否 則 就 執行 if 的 下 一 敘 述 。 所 以if 的 複 合 敘 述 不 一 定 會被 執 行 。


輸 入 一 個 成 績 , 判 斷 是 否 及 格演 算 法 ( 以 文 字 敘 述 法 記 錄 )1. 宣 告 變 數2. 輸 出 提 示 句3. 取 得 使 用 者 在 鍵 盤 的 輸 入4. 如 果 輸 入 的 整 數 大 於 等 於 60, 則5. 輸 出 ” 及 格 ”6. 如 果 輸 入 的 整 數 小 於 60, 則7. 輸 出 ” 加 油 ”8. 結 束


score01.c 單 一 選 擇 解 題#include int main (void){int score;printf(" 請 輸 入 成 績 : ");scanf("%d", &score);if (score >= 60){ printf (“ 您 的 成 績 %d 已 經 及 格 !\n", score) ; }if (score < 60){ printf (“ 您 的 成 績 %d, 還 要 加 油 !\n", score) ; }printf(" 程 式 執 行 結 束 \n");return 0;}


score02.c 二 者 擇 一 解 題#include int main (void){int score;printf(" 請 輸 入 成 績 : ");scanf("%d", &score);if (score >= 60){ printf (“ 您 的 成 績 %d 已 經 及 格 !\n", score) ; }else{ printf (“ 您 的 成 績 %d, 還 要 加 油 !\n", score) ; }printf(" 程 式 執 行 結 束 \n");return 0;}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!