• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
C Programming Language #1
 

C Programming Language #1

on

  • 767 views

 

Statistics

Views

Total Views
767
Views on SlideShare
575
Embed Views
192

Actions

Likes
0
Downloads
31
Comments
0

7 Embeds 192

http://aragornyeh.blogspot.tw 142
http://aragornyeh.blogspot.com 36
http://semicounterarch9.rssing.com 9
http://aragornyeh.blogspot.in 2
http://reader.aol.com 1
http://aragornyeh.blogspot.co.uk 1
http://aragornyeh.blogspot.se 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    C Programming Language #1 C Programming Language #1 Presentation Transcript

    • PROGRAMMING LANGUAGE #1 aragornyeh@gmail.com
    • Class Rule
    • C Programming Language
    • C • 1972 AT&T Bell Laboratory • Develop UNIX Application • Dominant language for system software
    • The Developers
    • C Programming Language 1. Computing Numbers 2. Handling Text
    • C, C++, JAVA, C#, Objective-C • Have the same SYNTAX. • Evolved in TIME • Procedural Vs. Object-Oriented
    • TextBook 第1章 C程式概觀
    • Dev-C++
    • DEV C++ PRACTICE How to write your First C Program
    • 學習一個新的程式語言 最佳的方式就是用它來寫程式。第一個程式是要印出 如下的文字: hello, world
    • Hello World Program
    • Hello World C Program #include <stdio.h> #include <stdlib.h> int main( ) { printf("hello, worldn"); system(“PAUSE”); return 0; }
    • C語言程式結構 p.1-5 • Preprocessor • Main function • Statement • …Other functions
    • C Program Structure #include <stdio.h> ……………………………………. main( ) { /* body of program goes here a sequence of declarations and statements */ return 0; }
    • 1.2 EXAMPLE
    • /* ch1 outline.c */ #include <stdio.h> #include <stdlib.h> #define Max 10 int square(int); int main( ) { int i; int total; int square_total = 0; total = 0; for (i=1; i<=MAX; i++) { total += i; } printf("The sum of 1+2+...+10 is %d.n", total); square_total = square(total); printf( "Its square is %d.n", square_total); system("PAUSE"); return 0; } int square(int value) { return(value * value); }
    • 1.3 Example /* ch1 first.c */ #include <stdio.h> /* header file */ #include <stdlib.h> int main( ) /* function of main( ) */ { printf("Hello, "); /* function statement */ printf("world.n"); printf("Learning C now.n"); system("PAUSE"); return 0; }
    • Comment 1. // This is my first program 2. /* Print text on the screen Calculate number of words End Program */
    • Preprocessor • #include <filename>
    • #include <stdio.h> stdio.h的實際意義為標準輸入輸出 printf( )函式的語法,是放在stdio.h裏
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Main function { <CODE> } Start Code Block End Code Block Programmingin C
    • printf function printf("Hello, "); printf("world.n"); printf("Learning C now.n");
    • Console Output Hello, world. Learning C now.
    • n 所代表的是換行字元(Newline character)
    • system(“PAUSE”); 將輸出結果暫停在螢幕上,待使用者按任意鍵後才跳 離。
    • return 0; 傳回值
    • Review /* ch1 first.c */ #include <stdio.h> /* header file */ #include <stdlib.h> int main( ) /* function of main( ) */ { printf("Hello, "); /* function statement */ printf("world.n"); printf("Learning C now.n"); system("PAUSE"); return 0; }
    • /* ch1 variable.c */ #include <stdio.h> #include <stdlib.h> int main( ) { int num; int square; num = 10; square = num * num; printf("Square of number %d is %d.n",num,square); system("PAUSE"); return 0; } 1.5 Example
    • int
    • Declaration int num; int square;
    • = num = 10; 指定數值給變數num
    • Multiplication square = num * num; num此時的值是10
    • printf() printf("Square of number %d is %d.n", num, square); Square of number 10 is 100.
    • /* ch1 many_var.c */ #include <stdio.h> #include <stdlib.h> int main( ) { int i , j, k; i = 10; j = 20; k= 30; printf("i + j + k = %d.n", i+j+k); system("PAUSE"); return 0; } 1.6 Example
    • Declaration of variables int i; int j; int k; int i, j, k;
    • Initialization of variables i = 10; j = 20; k = 30;
    • Declaration and Initialization int i=10, j=20, k=30; int i, j, k = 30;
    • Review
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration <Variable Type> <Variable Name> = <Expression>; Programmingin C int num = 10;
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration int num = 10; Programmingin C
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration Variable Type Programmingin C int num = 10;
    • int num = 10; Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration Variable Name Programmingin C
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration Expression (Value) Programmingin C int num = 10;
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration Terminator Programmingin C int num = 10;
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration int num; num = 10; Programmingin C
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration Variable declaration Set variable value Programmingin C int num; num = 10;
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Terminator Variable Declaration Programmingin C int x = 10; int y = 1 + 2;
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration int x = 10; int y = 1 + 2; Same as int x = 10, y = 1 + 2; Programmingin C
    • Copyright © BlueSignet LLC. All rights reserved. For more visit WiBit.Net Variable Declaration int y = 1 + 2; int y=1+2; Programmingin C Same expression
    • 1.9 EXERCISE
    • #include <stdio.h> #include <stdlib.h> int main( ) { printf("hello,"); printf(“how are you? n"); printf(“I am fine,"); printf(“thank you."); printf(“And you? n"); printf(“Over"); system(“PAUSE”); return 0; }
    • #include <stdio.h> #include <stdlib.h> int main( ) { int x=100, y=200, z=300; int total=0; total = x+y+z; printf(“x=%d, y=%d, z=%d n“, x, y, z); printf(“total = %d“, total); system(“PAUSE”); return 0; }
    • #include <stdio.h> #include <stdlib.h> int main( ) { int a=1, b=2, c=3; printf(“a0=%d, b0=%d, c0=%d n“, a, b, c); c=b; b=a; printf(“a1=%d, b1=%d, c1=%d n“, a, b, c); b=b+1; a=a*2; printf(“a2=%d, b2=%d, c2=%d n“, a, b, c); system(“PAUSE”); return 0; }
    • Homework #1 • 1.10 No.2 (P.26) • Write or Print in A4 Paper • Name & I.D.
    • C Programming is Easy! Any Question? aragornyeh@gmail.com
    • 1.7 Keyword Auto break case char const continue default do double else enum extern float for goto if int long register return short while signed sizeof static struct switch typedef union unsigned void volatile