1 / 15

CH-01

CH-01. 簡單程式. C程式風格. #include &lt;stdio.h&gt; void main() { printf(&quot;Hello C, KSUT <br>&quot;); }. C程式風格 ( 二 ). #include &lt;stdio.h&gt; void main() { printf( &quot; I am George. <br> &quot; ); printf( &quot; 我是張三 <br> &quot; ); }. C 風格 (DEV-C++ 版 ). #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;

carlos-wolf
Download Presentation

CH-01

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. CH-01 簡單程式

  2. C程式風格 #include <stdio.h> voidmain() { printf("Hello C, KSUT \n"); }

  3. C程式風格(二) #include <stdio.h>void main(){ printf("I am George. \n"); printf("我是張三 \n");}

  4. C風格(DEV-C++版) #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { printf("Hello C! KSUT \n"); system(“PAUSE”); /* 自動產生 */ return 0; /* 自動產生 */ }

  5. 基本資料型別 • 整數(4byte) int int a,b; • 長整數(8byte) long long c,d; • 單精確度實數(4byte) float float e,f; • 倍精確度實數(8byte) double double x,y; • 字元(1byte) char char s='A'; • 無void void z;

  6. C語言運算子 1.算術運算子︰+ ,- ,* ,/ , % 2.增量和減量運算子:++ , -- 3.關係運算子: > , < , >= , <= , == , != 4.邏輯運算子: ! , && , || 5.位元運算子: ~ , & , | , , >> , << 6.指定運算子:= , += , -= , *= , /= , %= , &= , |= , = , <<= , >>= 7.條件運算子: ? : 8.位址和指標運算子: & , * 9.長度運算子: sizeof()

  7. 算術運算子︰+ ,- ,* ,/ , % • 3 + 5 • 9 - 2 • 8 * 7 • 4.5 / 3 實數 • 5 / 2 整數 • 18 / 3 • 18 % 3 求餘數

  8. 增量和減量運算子:++ , -- • ++ 加一 • -- 減一 • 前置:先增減再參考 • 後置:先參考再增減 • a=5;a++; ++a; 例:a=8; b=3;c=a++ + ++b;

  9. 增量和減量運算子:++ , --(2) 例:a=3; b=8;c = --a - b++; printf("%d%d%d\n",a,b,c); 例:a=4; b=9;c = a-- - --b; printf("%d%d%d\n",a,b,c);

  10. 輸出 • 輸出一字串printf("XXXXXX \n"); • 輸出整數printf("%5d%5d\n",a,b);//假設a=5,b=123△△△△5△△123printf("Sum=%d \n",a); //文字與數值a=79Sum=79 • 輸出實數printf("%8.3f \n",a); //假設a=12.3△△12.300

  11. 輸入 • 輸入兩整數scanf("%d%d",&a,&b); • 輸入兩實數scanf("%f%f",&a,&b);

  12. 簡單練習 • 輸入二整數,輸出和及差#include <stdio.h>void main(){ /* 宣告變數 */ int a,b; scanf("%d%d",&a,&b); printf("sum=%d \n",a+b); printf("差=%5d \n",a-b);}

  13. 簡單練習(二) • 輸入二整數,輸出和、差、積、商、餘數 • 輸入一整數(三位數),求相反印出例輸入:675輸出:576 • 輸入圓的半徑,輸出面積與周長 • 輸入三角形的底與高,輸出面積

  14. 讀取字元 • char c,d; • scanf(“%c”,c); • c = getchar(); //要按 enter • d = getch(); //不必按 enter • putchar(‘A’); • putchar(65);

More Related