1 / 16

The C Language

The C Language. History of C. 西 元 1960 年 Algo 60 語 言 ( International Committe ) 西 元 1963 年 CPL 語 言 ( 劍 橋 與 倫 敦 大 學 ) 西 元 1966 年 BCPL 語 言 下 ( 劍橋大學 Martin Richards ) 西 元 1970 年 B 語 言 ( AT&T Ken Thompson ) 西 元 1972 年 C 語 言 ( AT&T Dennis Ritchie ).

hinda
Download Presentation

The C Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The C Language

  2. History of C 西 元 1960 年 Algo 60語 言 ( International Committe ) 西 元 1963 年 CPL 語 言 ( 劍 橋 與 倫 敦 大 學 ) 西 元 1966 年 BCPL語 言 下 ( 劍橋大學 Martin Richards ) 西 元 1970 年 B 語 言 ( AT&T Ken Thompson ) 西 元 1972年 C 語 言 ( AT&T Dennis Ritchie )

  3. Program I : The happiness is… 執行結果 #include <stdio.h> #include <stdlib.h> int main( ) { printf("「幸福」就是… "); printf("每天晚上能一覺到天亮!\n"); system("PAUSE"); return 0; }

  4. Program II : 5 + 7 = ?執行結果 a b c 5 7 12 5+7 #include <stdio.h> #include <stdlib.h> int main() { inta, b, c; a = 5; b = 7; c = a + b; printf("%d + %d = %d\n", a, b, c); system("PAUSE"); return 0; }

  5. Program III : How old are you ? #include <stdio.h> 執行結果 #include <stdlib.h> int main( ) { int myage; myage = 16; printf("I am %d years old. \n", myage); printf("Next year, I will be %d years old. \n", myage+1); system("PAUSE"); return 0; }

  6. How printf( ) work? • printf("Hello"); • printf("Hello\n"); • printf("%d",b); • printf("The temperature is "); printf("%d",b); printf(" degrees\n"); • printf("The temperature is %d degrees\n", b); • printf("%d +%d = %d\n", a, b,c);

  7. 資料型態 佔1 byte 佔4 bytes 佔4 bytes 佔2 bytes 佔4 bytes 佔8 bytes (character, 字元) char (integer, 整數) int (long integer, 長整數) long (short integer, 短整數) short (浮點數) float (倍精度浮點數) double

  8. How printf( ) work? • int (整數) uses %d • float (浮點數) uses %f • char (字元) uses %c • character strings(字串)use %s

  9. 變數 • 變數名稱要有意義,以增加程式的可讀性。(如num表數字、stud表學生人數) • 變數名稱的限制: • 不能使用C語言的關鍵字。 • 變數名稱的有效長度是前八位元。 • 可以是英文字母、數字或底線。 • 不能有空白字元。 • 第一個字元不能是數字。

  10. Program IV : a + b = ? 執行結果 #include <stdio.h> #include <stdlib.h> int main() { int a, b, c; printf("Enter the first value:"); scanf("%d", &a); printf("Enter the second value:"); scanf("%d", &b); c = a + b; printf("%d + %d = %d\n", a, b, c); system("PAUSE"); return 0; }

  11. Program V : How old are you ? #include <stdio.h> 執行結果 #include <stdlib.h> int main() { intyourage; printf("How old are you?"); scanf("%d", &yourage); printf("Next Year, you will be %d years old.\n", yourage+1); system("PAUSE"); return 0; }

  12. How scanf() work? • scanf("%d", &b); • int uses %d • float uses %f • char uses %c • character strings use %s • scanf("%d %d", &a,&b); • scanf("%d,%d", &a, &b); • 範例程式、執行結果

  13. 計算圓面積 • 已知:(輸入) 圓半徑 radius • 求: 圓面積 area • 運算式:(公式 ) pi = 3.14159; area = pi * radius * radius; • 輸出:圓面積(到小數位數第二位)(%.2f)

  14. 計算攝氏溫度轉華氏溫度 • 已知:(輸入) 攝氏溫度 C • 求: 華氏溫度 F • 運算式:(公式 F = 9/5 * C + 32) F = (float)C * 9 / 5 + 32; F = 9.0 / 5 * C + 32; • 輸出:華氏溫度 F 值為 xx.xx(%.2f)

  15. 計算BMI • 已知:(輸入) 身高 height 體重 weight • 求:BMI • 運算式: • BMI = weight / (height)2 (身高單位為公尺、體重單位為公斤。) • BMI= weight/(height*height/10000); • 輸出:你的 BMI 值為xx.xx(%.2f) 執行結果

More Related