การเขียนคำสั่งควบคุมขั้นพื้นฐาน 2

223 views
163 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
223
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

การเขียนคำสั่งควบคุมขั้นพื้นฐาน 2

  1. 1. (cos) (Windows)
  2. 2. 1. . . 1972 BCLP B ( Bell Laboratoories)
  3. 3. . . 1972 The C Programming Language
  4. 4. . . 1988 ANSI
  5. 5. 2.
  6. 6. 1. (Source Program) .c work.c
  7. 7. .c
  8. 8. 2. (Compile) (Build) A
  9. 9. 3. ( Link) printf () exe
  10. 10. # include < header file > 1 Main ( ) { Statements ; 2 }
  11. 11. 1 (Header File) main ( ) .h
  12. 12. # include < header_name> header_name printf #include <stdio.h> # include <stdio.h>
  13. 13. stdio.h include #include <stdio.h>
  14. 14. stdio.h .o include
  15. 15. 2. (Main Function) { } main ( )
  16. 16. 3. ( ) 1.
  17. 17. 2. 3. (;)
  18. 18. 4. 1 1 1 5.
  19. 19. (identifier) (Address )
  20. 20. 2
  21. 21. 1. 3 char a [20] :
  22. 22. 2. : Const data_type var = data ; data_type Var Data
  23. 23. 3 : 1 var_type var_name[,….]; 2 var_type var_name = data ; var_type var name data ( )
  24. 24. 3 (input ) (Process) (Qutput )
  25. 25. 1 : printf ( ) : 1 Printf (“ string_format” , data_list ) ; 2 Printf (“string_format” ) ; string_format (text ) %d n Data_list
  26. 26. format code %c char %d int 10 %s string
  27. 27. : Scanf ( “ string_format” , & address_list ) ; string_format %d Address_list &(Ampersand)
  28. 28. 3. : expression : Var = expression ; var Expression
  29. 29. 1. ; x A y Printf ( “data x=” ) ; scanf ( “%d ,&x ) ; Printf ( “data y=” ) ; scanf ( “%d ,&y )
  30. 30. 2. r = 2 + 3 * 2 ; 8 s = (2 + 3 ) * 2; 10 t = 2 + 3 * 2-1 ; 7
  31. 31. 3. Printf ( “r = x + y * 2 = %d n” , r ) ; Printf ( “r = (x + y X* 2 = %d n” , s ) ; Printf ( “r = x + y * 2-1 = %d n” , t ) ;
  32. 32. 8 (char ) 5.1 putchar ( ) 1 Putchar ( char_argument) ; putchar_argument
  33. 33. 1. ‘A’ char word1 „1‟ word2 char word1=‟A‟ , word2=‟1‟ 2. 1 putchar(word1);
  34. 34. 5.2 getchar ( ) 1 Enter 1 getchar ( ) ; 2 char_var = getchar ( ) ;
  35. 35. 1. printf ( “Key 1 Character = “ ) ; word = getchar ( ); 1 a Enter
  36. 36. 2 . word a ( word) printf ( “You key Character is = %cn”, word ) ;
  37. 37. 5.3 getch ( ) 1 Enter 1 getch( ) ; 2 char_var = getch 1( ) ;
  38. 38. 1. printf ( “Key 1 Character = “ ) ; word = getch ( ); 1 a Enter
  39. 39. 2. word a ( word ) printf ( “You key Character is = %cn”, word ) ;
  40. 40. 5.4 getche( ) 1 Enter 1 getche ( ); 2 char_var = getche ( ); char_var
  41. 41. 1. printf ( “Key 1 Character = “ ) ; word = getche ( ); 1 a Enter
  42. 42. 2. word a ( word ) printf ( “You key Character is = %cn”, word ) ;
  43. 43. (String) char [n] 6.1. puts( ) 6.2. gets( )
  44. 44. 6.1. puts( ) 1 puts ( string_argument ) ; string_argument
  45. 45. 1. word Char word [15] = “*Example * “ ; 2. puts Puts ( word ) ;
  46. 46. 6.2 gets ( ) Enter 1 gets ( ); 2 string_var =gets ( ) ; string_var
  47. 47. 1. Enter gets (word) ; 2. printf ( “You name is = %sn”,
  48. 48. 1.
  49. 49. 1. #include <stdio.h> 2. (remark) /* calculate// cal1.c*/
  50. 50. 3. int n1,n2,result;( 3 n1,n2 result ) 4. printf(“*calculate Add*nn*);n
  51. 51. 5. printf (“key number 1 =”) ; scanf(“%d”,&n1); key number 1 =( ) 6. result= n1+n2; ( n1 n2 result)
  52. 52. 7. _ printf (“n**Result =%dn” ,result); ( ** Result = result %d )
  53. 53. 2.
  54. 54. 1. 1.1 ) const char line[20] = “**************”; const int n3 =2; 1.2)
  55. 55. 2. printf("*Calculate Value * nn"); printf(line); printf("n key number 8 = "); scanf("%d" , &n8); printf(" key number ; = ");
  56. 56. result = n8 + n; * nA; 5. printf("n %d + %d * %d = %d n" , n8, n;, nA, result);
  57. 57. 3. 1. printf (“n key syudent name :”)
  58. 58. 2. result = (score * 100) /250 ; 3. printf(“n * percentage = %f n” , result) ;
  59. 59. 4. 1. char name[30]; int code, sum,num; float avg;
  60. 60. 2. printf(“ code =>”); scanf(“%d”, &code); printf(“ name =>”); scanf(“%s”, &name); printf(“ summit =>”); scanf(“%d”, &sum); printf(“ number =>”); scanf(“%d”,
  61. 61. 3. avg = sum/num; 4. printf(“* average = % .2f n” , avg);
  62. 62. 1. char name[40]; float budget, maint, pub, remain ;
  63. 63. 2. printf(“project name = ”); scanf(“%s” , name); printf(“budget = ”) ; scanf(“%f” , &budget) ; 3. maint = budget * 20/100 ; pub = (budget - maint) * </8BB ;
  64. 64. 4. printf(“n ** maintenance = %.2f n” , maint); printf(“n ** public utility = %.2f n” , pub); printf(“n ** remain = %.2f n” , remain);
  65. 65. 6/2 1. 4 2. 6 3. 7 4. 12 5.

×