กF    Printf();
      Printf();
     Scanf();
     Scanf();

           ก      ก   กก
ก                          ก           F

        printf     F
        scanf          F   F       ก F         F

printf    scanf ก ก F          F stdio.h           กF   F
กF printf     scanf F F

                 #include<stdio.h>
กF            printf()
                                       printf()
printf()             ก        F
   1.            F                ก
       printf( F                      );
      F printf( Hello world );
   2.            ก
       printf(                    ก               ,   );
                                                      F
           F printf( My age is %dn , myAge);
ก
format code
    %d               ก                       (int, short, unsigned short, long, unsigned
              long
   %u               ก                           ก (unsigned short, unsigned long
   %o               ก               ก
   %x               ก               ก                        ก
   %f               ก                     (float, double, long double)
   %e               ก                        ก                  E ( e) กก (float,
              double, long double)
   %c               ก             ก 1 (char)
   %s               ก             F   (ก       กก F 1 )
   %p               ก                  F (pointer)
F
main()
{
  int i =12345;
  float x=350.875;
       printf( %dn ,i);
       printf( %fn ,x);
}
F
12345
350.875000
กF    scanf();
                        scanf();
Scanf( ) ก F           F       ก        F
 •         กF        F                    C
  ก ก                    scanf( )
 •            F    ก keyboard F         ก F
           F F              (memory address   )
          ก ก F function scanf( ) F F           F
      F (address)                 F         F
   function scanf( )
ก      F       กF         scanf();
                                        scanf();
     scanf( format string , &variable);
1. format string             Fก              ก   ก
  F
2. &variable ( ก         F        F              ก
 F )             F                    Fก F           F
&name
F ก   F      กF   scanf();
                            scanf();
F     F
 F
int month ,year;
scanf( %d %d , &month, &year);
      ก ก      F               F
int i;
float x;
scanf( %d %f ,&i,&x);
F
#include<stdio.h>
#include<conio.h>
int main()
{
  int year;
  float salary;
  clrscr();
  printf(“Insert year experience and salary : ”);
  scanf(“%d %f”,&year,&salary);
  printf(“You worked for %d years.n”,year);
  printf(“Your salary is %.2fn”,salary);
  return(0);
}

บทที่ 6 1 ฟังก์ชัน printf scanf [slide]

  • 1.
    กF Printf(); Printf(); Scanf(); Scanf(); ก ก กก
  • 2.
    ก F printf F scanf F F ก F F printf scanf ก ก F F stdio.h กF F กF printf scanf F F #include<stdio.h>
  • 3.
    กF printf() printf() printf() ก F 1. F ก printf( F ); F printf( Hello world ); 2. ก printf( ก , ); F F printf( My age is %dn , myAge);
  • 4.
    ก format code %d ก (int, short, unsigned short, long, unsigned long %u ก ก (unsigned short, unsigned long %o ก ก %x ก ก ก %f ก (float, double, long double) %e ก ก E ( e) กก (float, double, long double) %c ก ก 1 (char) %s ก F (ก กก F 1 ) %p ก F (pointer)
  • 5.
    F main() { inti =12345; float x=350.875; printf( %dn ,i); printf( %fn ,x); }
  • 6.
  • 7.
    กF scanf(); scanf(); Scanf( ) ก F F ก F • กF F C ก ก scanf( ) • F ก keyboard F ก F F F (memory address ) ก ก F function scanf( ) F F F F (address) F F function scanf( )
  • 8.
    F กF scanf(); scanf(); scanf( format string , &variable); 1. format string Fก ก ก F 2. &variable ( ก F F ก F ) F Fก F F &name
  • 9.
    F ก F กF scanf(); scanf(); F F F int month ,year; scanf( %d %d , &month, &year); ก ก F F int i; float x; scanf( %d %f ,&i,&x);
  • 10.
    F #include<stdio.h> #include<conio.h> int main() { int year; float salary; clrscr(); printf(“Insert year experience and salary : ”); scanf(“%d %f”,&year,&salary); printf(“You worked for %d years.n”,year); printf(“Your salary is %.2fn”,salary); return(0); }