Programming Language Telling the computer what to do

  • Slides: 20
Download presentation
Programming & Language Telling the computer what to do 2005. 04 綠園

Programming & Language Telling the computer what to do 2005. 04 綠園

Programming n Why programming? n n For solving problem. Who program the program? n

Programming n Why programming? n n For solving problem. Who program the program? n The programmer is programming a program!

The Programmer Convert problem solutions into instruction for the computer. n Coordination meetings with

The Programmer Convert problem solutions into instruction for the computer. n Coordination meetings with users, managers, system analysts, and with peers who evaluate your work. n

The Programming Process n n n defining the problem planning the solution coding the

The Programming Process n n n defining the problem planning the solution coding the program testing the program, documenting the program.

Preparing a program for execution

Preparing a program for execution

The C Language 2004. 09 綠園

The C Language 2004. 09 綠園

History of C n n n 西 元 1960 年 Committe ) 西 元

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

Program I : Hello, I am … #include <stdio. h> #include <stdlib. h> int

Program I : Hello, I am … #include <stdio. h> #include <stdlib. h> int main( ) { printf("Hello, I am Jenny!n"); printf("This is output from my first program!n"); system("PAUSE"); return 0; }

Program II : 5 + 7 = ? 執行結果 #include <stdio. h> #include <stdlib.

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

Program III : How old are you ? #include <stdio. h> #include <stdlib. h>

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; }

How printf( ) work? n n n printf("Hello"); printf("Hellon"); printf("%d", b); printf("The temperature is

How printf( ) work? n n n printf("Hello"); printf("Hellon"); printf("%d", b); printf("The temperature is "); printf("%d", b); printf(" degreesn"); printf("The temperature is %d degreesn", b); printf("%d + %d = %dn", a, b, c);

資料型態 (character, 字元) char (integer, 整數) int (long integer, 長整數) long (short integer, 短整數)

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

How printf( ) work? n n int (整數) uses %d float (浮點數) uses %f

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

Program IV : a + b = ? 執行結果 #include <stdio. h> #include <stdlib.

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 = %dn", a, b, c); system("PAUSE"); return 0; }

Program V : How old are you ? #include <stdio. h> 執行結果 #include <stdlib.

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

How scanf() work? n scanf("%d", &b); n n n n int uses %d float

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