C語言

C程式的編譯器

DEV C++

Sublime text 3 

Visual Studio

notepad++

DEV C++

~課程開始~

C程式的結構

  • 前置處理指令
    • 用在於需要使用到的函數原型定義
#include <stdio.h>
#include <stdlib.h>
  • <stdio.h>
    • printf() / scanf()
  • <stdlib.h>
    • system()

#include 指令

int main(){
   ...
}

C 程式區塊

  • main()
    • 程式執行時最先執行此區塊
  • int -- 整數
    • 此區塊傳回值型態

每一個區塊內的每一個行程式後面都要加上;

int main(){
    ...
    system("pause");
    return 0;
}
  • system("pause");
    • 讓程式暫停
  • return 0;
    • 執行完畢後傳回一個整數資料
#include <stdio.h>
#include <stdlib.h>

int main(){
    
    system("pause");
    return 0;
}

撰寫一個C程式中必要的程式碼

輸入/輸出 指令

輸出

printf("");
#include <stdio.h>
#include <stdlib.h>

int main(){
    printf("資研社");
    system("pause");
    return 0;
}

/n  (換行符號)

#include <stdio.h>
#include <stdlib.h>

int main(){
    printf("資研社/n");
    system("pause");
    return 0;
}

輸入

  • 在輸入一個數字之前,必須要先指定一個變數給他
  • 給使用者一個提示字元 --> printf()
#include <stdio.h>
#include <stdlib.h>

int main(){
    int x;
    printf("請輸入一個整數: ");
    scanf("%d", &x);
    printf("你輸入的數字是%d\n",x);
    system("pause");
    return 0;
}

%d : 數字   

& : 繫結

C

By kellyhu0109