Upcoming SlideShare
×

# โครงสร้างภาษาซี

4,490 views

Published on

Published in: Education
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
4,490
On SlideShare
0
From Embeds
0
Number of Embeds
2,497
Actions
Shares
0
25
0
Likes
1
Embeds 0
No embeds

No notes for slide

### โครงสร้างภาษาซี

1. 1. F F F Turbo C++ Version 3.0
2. 2. F F F F F F F F (Source Program) F (Executable Program) F ( )
3. 3. F F F (Interpreter) F (Compiler)
4. 4. F F F F F F FF F F F F F F F
5. 5. F void main(void) Preprocessor directive { Global Declarations Local Declarations main function Statements ; User define functions } int function () { User define functions Local Declarations Statements ; F F F F F F F }
6. 6. F Preprocessor Directive F F F F F F F F F F # F 2 directives #include F F #define F F #include #define #undef #if #ifdef #ifndef #else #elif #endif #line #error #pragma
7. 7. F #include F #include < F > #include F F #include <stdio.h> ( F F stdio.h F ) #include <mypro.h> ( F F mypro.h F ) <> F directory F F “ ” F directory F
8. 8. F #define F #define F F F #define START 10 ( F START = 10) #define A 3*5/4 ( F A=3*5/4) #define pi 3.14159 ( F pi = 3.14159) #define sum(a,b) a+b ( F sum( 1, 2) = 1+ 2
9. 9. F (Global Declarations) F F F F F Function Prototype F F F F int summation(float x, float y) ; ( function summation) int x,y ; ( x,y ) float z=3; ( z )
10. 10. F (Global Declarations) F #include <stdio.h> int feet,inches; void main() { feet = 6; inches = feet * 12; printf("Height in inches is %d",inches); } Height in inches is 72
11. 11. F (Main Function) F F F F main() F { } F F (Statement) F F F F F ; (Semicolon) #include <stdio.h> void main(void) { ... Statement ; }
12. 12. F (Main Function) F #include <stdio.h> int feet,inches; void main() { feet = 6; inches = feet * 12; printf("Height in inches is %d",inches); } Height in inches is 72
13. 13. F F F (User Define Function) F F F F F F F (Statement) F F F F F #include <stdio.h> int function() void main(void) { ... Statement ; } int function() { Statement ; ... return (int value); }
14. 14. F F F (User Define Function) F #include <stdio.h> int Feet2Inch(int); int feet,inches; void main() { feet = 6; inches = Feet2Inch(feet); printf("Height in inches is %d",inches); } int Feet2Inch(int f) { return f*12; } Height in inches is 72
15. 15. F (Program Comments) F F ( ) F F FF F F F F F (comments) F2 // F /* */ F
16. 16. F (Program Comments) F #include <stdio.h> // Change Feet to Inches void main() // main function { // Start int feet,inches; feet = 6; // feet 6 inches = feet * 12; // inches feet * 12 printf("Height in inches is %d", inches); // write inches } // Stop Height in inches is 72
17. 17. F printf() F F printf(“control format string”, variable list …); control format string F F F F F variable list F F F F F F
18. 18. 1 F folder 517111/ F F hello.c F F F hello world F turbo c F2 Save Alt+F9 Compile Ctrl+F9 Compile & Run Alt+F5 Output F
19. 19. F #include <stdio.h> Backslash n void main() { F printf(“Hello worldn"); printf(“Welcome to Computer Programming 1"); return ; } Hello world Welcome to Computer Programming 1
20. 20. #include <stdio.h> main () { clrscr(); F F …. getch(); F F F }
21. 21. F Control F Backslash F 3 FF F F F F n F backslash F n F t F 1 tab F hh hh xhh F 41 = 'A', 42 = 'B' a F " "
22. 22. F #include <stdio.h> main() { printf("%d %5.2f %s", 12, 20.3, "Example"); } 12 20.30 Example %d %5.2f %s
23. 23. (Format String) %d F %u F F %f F %e F %c F %s F (String) %% F % %o F %x F
24. 24. F #include <stdio.h> #define x 65 main() { printf("%d %c %o %xn", x, x, x, x); printf(“x = %d”, x); } 65 A 101 41 X = 65
25. 25. F F F F F F F F %5d 5 F %5.2f 5 F 2 F F %d %5d F %f %5.2f 12 12 ___12 1.2 1.200000 _1.20 123 123 __123 1.234 1.234000 _1.23 1234 1234 _1234 12.345 12.345000 12.35 12345 12345 12345 123.456 123.456000 123.46
26. 26. X in decimal = 65 2 X in octadecimal = 101 X in Hexadecimal = 41 Y = 1.234 F F print.c Y = 1.23e+00 #define F CH = %C X F 65 SU = “Sipakorn university” Y F 1.23456 CH F ‘C’ SU F “Silpakorn university” FF F F
27. 27. F C F2 F (Constant) (Variable) F F FF F F F F C F (Character variable) F (Integer variable) F (Float variable)
28. 28. ; int i; i F integer float realnum; realnum F float char ch; ch F character
29. 29. F F F ( F ) char 1 -128 127 1 short -128 127 1 int -32768 32767 2 long -232 232-1 4 float 3.4E+/-38 (7 F) 4 double 1.7E+/-308 (15 F) 8
30. 30. F (statement) F F 1. F int i; int j; int k; 2. F F int i, j, k;
31. 31. F F F F C (statement) F F F F F = F F ; F int i = 5; F F int i = 5, k = 3, y;
32. 32. (Identifier) (Identifier) F F F F F F F F F F ( F ) F F _ F F (Underscore) _ F F F F !, @, #, \$, %, ^ F F F F NAME, name, Name, NamE F Reserve Words C F Function F Library C
33. 33. Reserve Words C auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static While asm _cs _ds _es _ss cdecl far huge interrupt near pascal _export
34. 34. F F #include <stdio.h> #include <stdio.h> void main () void main () { { int age; int age = 20; char sex; char sex = ‘ f ’; float grade; float grade = 3.14; char name[10] = age = 20; “malee” sex = ‘ f ’; grade = 3.14; printf(“you are } %sn”,name); ... }
35. 35. F F F a + b x = y F c = a + b x == y F F ++i F F F
36. 36. F - ++ -- ! sizeof (type) * / % + - < <= > >= F == != AND && OR || ?: F F = += -= *= /= %=
37. 37. 3 F F triangle.c F F F F Area = ½ * *
38. 38. F scanf() F F F scanf(“format string”, address list …); format string F F F F address list F F F
39. 39. F #include <stdio.h> void main() { int x ; scanf("%d",&x); printf("%d %c", x, x); return ; } 66 65 66 B 65 A
40. 40. F #include <stdio.h> void main() { char s1[80], s2[80] ; scanf("%[0-9]%[a-zA-Z]", s1, s2); printf("%s %s", s1, s2); return ; } 1234test test1234 1234 test test
41. 41. F Input Base = 12.0 Input Base = 3.2 Input Height = 6.0 Input Height = 1.2 Area of triangle is 36.00 Area of triangle is 1.92 #include <stdio.h> void main() { float b,h,area ; printf("Input Base = "); scanf("%f",&b); printf("Input Height = "); scanf("%f",&h); area = 0.5*b*h ; printf("Area of triangle is %5.2f",area); return ; }
42. 42. 4 F F circle.c F F F PI F 3.14159 F Area = PI* ( )2
43. 43. F Input Radias = 12.0 Area of circle is 452.39 /* program to calculate area of a circle */ #include <stdio.h> #define PI 3.14159 main() { float radius, area; printf(“Input Radius = ?"); scanf("%f", &radius); area = PI * radius * radius; printf("Area of circle is %7.2f ", area); }
44. 44. 5 F F donut.c F F 2 F PI F 3.14159 F F