บทที่ 2

227 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
227
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

บทที่ 2

  1. 1. 2 C C Denis Ritchie1970 UNIX) C C Middle –leverlanguage) C compiled Language) (Compiler) Compile) Machine Language) C C
  2. 2. Int main (void){ Header Files) C#include< >#include “ ”#include<stdio.h>
  3. 3. h 1 stdio.h Global (Global Variables) Functions) C 1 Main() 1 1 Local (Local Variables) (Statements)C ;
  4. 4. C C Case SensitiveTest, test C ; Return Value) Comment)
  5. 5. 2-2 Comment 2 – 1 Identifier)1. _2. 2 _3. _4. 315.6. C
  6. 6. A $sum Student_name Student Name _SystemName 2names A1 int C C C 4 Void Type (Void) Integer Type (int) C 3 short int,int long int 2-1Short int 2 16 -32,768 32,768 0 65,535
  7. 7. Int 2 16 -32,768 32,768(16 0 65,535Int 4 32 - 2,147,486,643(32 2,147,486,643 4,294,967,295 0Long int 4 32 - 2,147,486,643 2,147,486,643 4,294,967,295 0 Character Type (char) A-Z 0-9 ACSII (American Standard Code Information Interchange) 1 1271 8 Floating Point Type (flat) 3 float,double long double 2-2 2-2float 4 32 -38 38
  8. 8. 3.4-10 3.4-10double 8 64 - 308 308 1.7*10 1.7*10long double 10 80 - 4932 4932 3.4*10 1.1*10 C 2 Global Local#include<stdio.h>int total; /* Global */main(){int price,money; /* Local*/
  9. 9. …} 2-3int total = 0;int total =0,sumint total =0,sum=0;total = 50;total = total+sumscanf(“%d”,&total);
  10. 10. 2-2#include<stdio.h>/* Global*/int sum = 0;int main(void){/* Local */int a;int b;int c;/*printf(“nWelcome. This Program addsn”);printf(“threenumbers.Enter three numbersn”);printf(“in the form: nnn nnn nnn <retur>n”);scanf(“%d %d %d”,&a,&b,&c);/* a,b c sum*/sum=a+b+c;
  11. 11. printf(“The total is: %dn”,sum);printf(“Thant you. Have a good day.n”);return 0;}Welcome. This Program addsThree numbers. Enter three numberIn the form: nnn nnn nnn <return>11 22 23The total is: 56Thank you. Have a good day.([
  12. 12. (float)a(int)a 2-3#include<stdio.h>int main(void){float a= 25.3658;printf(“Value of a : %n”,a);printf(“Value of a when set is integer : %dn”,(int)a);return 0;}Value of a : 25.365801Value of a when change is integer : 25 Constants) Constants
  13. 13. Const[const folat a = 5.23;const int b = a%2; 2-4#include<stdio.h>imt main(void){const float pi = 3.14159;float radius;radius = 3;printf(“Value of pi : %fn”,pi);printf(“Value of area : %fn”,pi*(radius*radius));return 0;}Value of pi : 3.141590Value of area : 28.274311
  14. 14. constantInteger Constantsconst int a = 5;Floating-Point Constantsconst float b = 5.6394;Character Constants‘’const char b = ‘t’;String Constants“”“”“h”“Hello worldn”“HOW ARE YOU”“Good Morning!” 2-5#includ<stdio.h>int main(void)
  15. 15. {const int a = 3; /*Integer Constats*/const flat b = 3.14159; /*Floating – Point Constants*/const cahr c = ‘P’; /*Character Constants*/printf(“Value of a: %dn”,a);printf(“Value of b: %dn”,b);printf(“Value of c: %dn”,c);printf(“Good Bye”); /*String Constants*/return 0;}Value of a : 3Value of b : 3.141590Value of c : PGood ByeStatements statements c
  16. 16. c 6Expression Statement Compound Statement 2 1. Expression Statement Single Statement Statement ; statement C ; Statement a = 2;printf(“x contains %d, y contains %dn”,x,y);Compound Statement Block { } Statement Main C Compound StatementFlowchart)
  17. 17. 1. Terminator 2. Process 3.Decision 4.Data 5.Manual Input
  18. 18. 6.Display 7.Predefined Process8.Connect 9. Arrow 31.
  19. 19. 2.
  20. 20. if…else3. do….while

×