1 / 14

程式設計

程式設計. 基本輸出入方法 (1). Printf() 列印格式化資料到標準輸出裝置. #include &lt;stdio.h&gt; main() { printf(&quot;hello, world<br>&quot;); }. 函數參數 (string). 函數名稱. Printf() 列印格式化資料到標準輸出裝置 ( 續 ). printf (&quot;Hello, World<br>&quot;); 指示電腦做列印動作 列印出括號內字串 ( &quot; &quot; ) 整個指令稱為一個 statement 所有指令都要有結束符號 ( ; ) 跳脫字元 ( ) 指示電腦做硬體的控制動作

allene
Download Presentation

程式設計

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. 程式設計 基本輸出入方法(1)

  2. Printf() 列印格式化資料到標準輸出裝置 #include <stdio.h> main() { printf("hello, world\n"); } 函數參數 (string) 函數名稱

  3. Printf() 列印格式化資料到標準輸出裝置(續) • printf("Hello, World\n"); • 指示電腦做列印動作 • 列印出括號內字串("") • 整個指令稱為一個 statement • 所有指令都要有結束符號 (;) • 跳脫字元 (\) • 指示電腦做硬體的控制動作 • \n是跳行的動作

  4. 跳脫字元

  5. printf 列印格式化資料到標準輸出裝置 • 輸出格式 int printf(“格式字串”[,$參數.....);

  6. scanf從標準輸入裝置讀入格式資料 • 輸入格式 int scanf(“格式字串”[,$參數.....);

  7. 基本輸入輸出函數 輸出函數 printf, puts,putchar, putch, putc 輸入函數 scanf, gets, getc, getch, getche, getchar

  8. 輸出函數

  9. printf()輸出(語法一) 1 #include<stdio.h> 2 main(){ 3 printf("Taiwan University.\n"); 4 } Taiwan University.

  10. printf()格式化輸出(語法二) 1 #include<stdio.h> 2 main(){ 3 int a=9, b=6, answer; 4 answer = a-b; 5 printf("The answer:%i-%i = %i.\n",a, b, answer); 6 } The answer:9-6 = 3.

  11. 影響數值輸出的因子 • 資料轉換型態 • 資料的欄寬和精確度 • 帶有\的字元常數 • ASCII字元輸出

  12. printf()函數資料轉換型態

  13. 八進位、十六進位轉換 1 #include<stdio.h> 2 main(){ 3 int a = 69; 4 printf("The ASCII Code of %i is %c.\n", a, a); 5 printf("The Octal value of %i is %o.\n", a, a); 6 printf("The Hexadecimal value of %i is %x.\n", a, a); 7 } The ASCII Code of 69 is E. The Octal value of 69 is 105. The Hexadecimal value of 69 is 45.

  14. 顯示資料的欄寬和精確度 • 語法一 • %ni e.g. %6i, %02i • 語法二 • %-nd e.g. %-6d +靠右 前面補0 -靠左

More Related