程式設計基礎(C)第02講例程
阿新 • • 發佈:2019-10-06
2.1 first.c
#include <stdio.h> int main(void) /* 一個簡單的C程式 */ { int num; /* 定義一個名為num的變數 */ num = 1; /* 為num賦一個值 */ printf("I am a simple "); /* 使用printf函式() */ printf("computer.\n"); printf("My favorite number is %d because it is first.\n",num); return 0; }
2.2 fathm_ft.c
// fathm_ft.c -- 把2英尋轉換成英尺 #include <stdio.h> int main(void) { int feet, fathoms; fathoms = 2; feet = 6 * fathoms; printf("There are %d feet in %d fathoms!\n", feet, fathoms); printf("Yes, I said %d feet!\n", 6 * fathoms); return 0; }
2.3 two_func.c
/* two_func.c -- 一個檔案中包含兩個函式 */
#include <stdio.h>
void butler(void); /* ANSI/ISO C 函式原型 */
int main(void)
{
printf("I will summon the butler function.\n");
butler();
printf("Yes. Bring me some tea and writeable DVDs.\n");
return 0;
}
void butler(void) /* 函式定義開始 */
{
printf("You rang, sir?\n