การเขียนคำสั่งควบคุมขั้นพื้นฐาน 2
Upcoming SlideShare
Loading in...5
×
 

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

on

  • 204 views

 

Statistics

Views

Total Views
204
Views on SlideShare
204
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

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

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

  • (cos) (Windows)
  • 1. . . 1972 BCLP B ( Bell Laboratoories)
  • . . 1972 The C Programming Language
  • . . 1988 ANSI
  • 2.
  • 1. (Source Program) .c work.c
  • .c
  • 2. (Compile) (Build) A
  • 3. ( Link) printf () exe
  • # include < header file > 1 Main ( ) { Statements ; 2 }
  • 1 (Header File) main ( ) .h
  • # include < header_name> header_name printf #include <stdio.h> # include <stdio.h>
  • stdio.h include #include <stdio.h>
  • stdio.h .o include
  • 2. (Main Function) { } main ( )
  • 3. ( ) 1.
  • 2. 3. (;)
  • 4. 1 1 1 5.
  • (identifier) (Address )
  • 2
  • 1. 3 char a [20] :
  • 2. : Const data_type var = data ; data_type Var Data
  • 3 : 1 var_type var_name[,….]; 2 var_type var_name = data ; var_type var name data ( )
  • 3 (input ) (Process) (Qutput )
  • 1 : printf ( ) : 1 Printf (“ string_format” , data_list ) ; 2 Printf (“string_format” ) ; string_format (text ) %d n Data_list
  • format code %c char %d int 10 %s string
  • : Scanf ( “ string_format” , & address_list ) ; string_format %d Address_list &(Ampersand)
  • 3. : expression : Var = expression ; var Expression
  • 1. ; x A y Printf ( “data x=” ) ; scanf ( “%d ,&x ) ; Printf ( “data y=” ) ; scanf ( “%d ,&y )
  • 2. r = 2 + 3 * 2 ; 8 s = (2 + 3 ) * 2; 10 t = 2 + 3 * 2-1 ; 7
  • 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 ) ;
  • 8 (char ) 5.1 putchar ( ) 1 Putchar ( char_argument) ; putchar_argument
  • 1. ‘A’ char word1 „1‟ word2 char word1=‟A‟ , word2=‟1‟ 2. 1 putchar(word1);
  • 5.2 getchar ( ) 1 Enter 1 getchar ( ) ; 2 char_var = getchar ( ) ;
  • 1. printf ( “Key 1 Character = “ ) ; word = getchar ( ); 1 a Enter
  • 2 . word a ( word) printf ( “You key Character is = %cn”, word ) ;
  • 5.3 getch ( ) 1 Enter 1 getch( ) ; 2 char_var = getch 1( ) ;
  • 1. printf ( “Key 1 Character = “ ) ; word = getch ( ); 1 a Enter
  • 2. word a ( word ) printf ( “You key Character is = %cn”, word ) ;
  • 5.4 getche( ) 1 Enter 1 getche ( ); 2 char_var = getche ( ); char_var
  • 1. printf ( “Key 1 Character = “ ) ; word = getche ( ); 1 a Enter
  • 2. word a ( word ) printf ( “You key Character is = %cn”, word ) ;
  • (String) char [n] 6.1. puts( ) 6.2. gets( )
  • 6.1. puts( ) 1 puts ( string_argument ) ; string_argument
  • 1. word Char word [15] = “*Example * “ ; 2. puts Puts ( word ) ;
  • 6.2 gets ( ) Enter 1 gets ( ); 2 string_var =gets ( ) ; string_var
  • 1. Enter gets (word) ; 2. printf ( “You name is = %sn”,
  • 1.
  • 1. #include <stdio.h> 2. (remark) /* calculate// cal1.c*/
  • 3. int n1,n2,result;( 3 n1,n2 result ) 4. printf(“*calculate Add*nn*);n
  • 5. printf (“key number 1 =”) ; scanf(“%d”,&n1); key number 1 =( ) 6. result= n1+n2; ( n1 n2 result)
  • 7. _ printf (“n**Result =%dn” ,result); ( ** Result = result %d )
  • 2.
  • 1. 1.1 ) const char line[20] = “**************”; const int n3 =2; 1.2)
  • 2. printf("*Calculate Value * nn"); printf(line); printf("n key number 8 = "); scanf("%d" , &n8); printf(" key number ; = ");
  • result = n8 + n; * nA; 5. printf("n %d + %d * %d = %d n" , n8, n;, nA, result);
  • 3. 1. printf (“n key syudent name :”)
  • 2. result = (score * 100) /250 ; 3. printf(“n * percentage = %f n” , result) ;
  • 4. 1. char name[30]; int code, sum,num; float avg;
  • 2. printf(“ code =>”); scanf(“%d”, &code); printf(“ name =>”); scanf(“%s”, &name); printf(“ summit =>”); scanf(“%d”, &sum); printf(“ number =>”); scanf(“%d”,
  • 3. avg = sum/num; 4. printf(“* average = % .2f n” , avg);
  • 1. char name[40]; float budget, maint, pub, remain ;
  • 2. printf(“project name = ”); scanf(“%s” , name); printf(“budget = ”) ; scanf(“%f” , &budget) ; 3. maint = budget * 20/100 ; pub = (budget - maint) * </8BB ;
  • 4. printf(“n ** maintenance = %.2f n” , maint); printf(“n ** public utility = %.2f n” , pub); printf(“n ** remain = %.2f n” , remain);
  • 6/2 1. 4 2. 6 3. 7 4. 12 5.