3




C

                                                          C

                                                          Standard

             Output File      Standard Input File   3-1




                    3-1

             Standard Input
File              Buffered



Standard Output
File




                              C       printf



Printf (“[             ”,[
3–2                   Output




                           Input           Output       3 -1

        3–1


               char               -                 c   %c
            short int            h                  d   %hd
                int               -                 d   %d
             long int          I or L               d   %Ld
               float              -                 f   %f
              double              -                 f   %f
           long doule             L                 f   %Lf




%[

                        3- 2

        3 -2

               %d                  %4d
   12          12                    12
123            123                 123
1234           1234                1234
12345          12345               12345
                               float

%[
printf(“%7.2f”,23.35000);
                                        5                   4

          1                             2

                      23.35



1. printf(“%d%c%f”,23, „z‟,4.1);



                      23z4.100000




2. printf(“%d %c %f”, 23. „z‟, 4.1);



           23 z 4.100000
                      1

3.        int num1 = 23;
char zee = „z‟;
float num2 = 4.1;
printf(“%d %c %f”, num1, zee, num2);



           23 z 4.100000
4.        printf(“%dt%ct%5.1f”, 23, „z‟, 14.2);
printf(“%dt%ct%5.1f”, 107, „A‟, 53.6);
printf(“%dt%ct%5.1f”, 1754, „F‟, 122.0);
printf(“%dt%ct%5.1f”, 3, „P‟, 0.1);



                      23                    z       14.2
                      107                   A       53.6
                      1754                  F       122.0
                      3                      P      0.1
5. printf(“The number is %6d”, 23);
The number is         23
        C




                                  Back-slash character       3-3

            3-3     Back-slash character


            „0‟         Null Character
            „a‟              Alert
            „b‟           Backspace
            „t‟           Horizontal
            „n‟             Newline
            „v‟           Vertical tab
             „f‟          Form feed
            „r‟         Carriage return
              „‟         Single quote
            „”‟          Double quote
            „‟            Backslash



1. printf(“%d %d %dn”, 44, 55);
44 55 0
                                 3                   2

2. printf(“%d %dn”, 44, 55, 66);
44 55
                                      2                  3    3



3. long int x = 444446766;
printf(“%dn”, x);
-18386


                                 Ld



                                       C    scanf
Scanf(“[               ”,[




                        3-3



                                            Enter



                                                    Error



1. 214 156 14z
scanf(“%d%d%d%c”, &a, &b, &c, %d);
                      14      z         c



           scanf(“%d%d%d %c”, &a, &b, &c, %d);
2. 2314 15 2.14
scanf(“%d %d %f”, &a, &b, &c);



3. 14/26 25/66
scanf(“%2d/%2d %2d/%2d”, &num1, &num2, &num3, &num4);



4. 11-25-56
scanf(“%d-%d-%d”,&a, &b, &c);



1. int a = 0;
scanf(“%d”,a);
printf(“%d/n”,a);
234                  (Input)
                                 0                      (Output)
                                         &       a

                                         error

2. float a = 2.1;
scanf(“%5.2f”,&a);
printf(“%5.2f”,a);




3. int a;
Int b;
scanf(“%d%d%d”,&a, &b);
Printf(“%d %d/n”, a, b);
5 10                 (Input)
                      5 10                   (Output)
                                     3                           2   scanf

            2                                             3



                                                     conio.h

getch                                                    1

                             Enter




            ch = getch();
getche                               getch



ch = getch();
getchar                                                      1

                                     Enter
ch = getchar(0;



        3-1              “Nothing”

                   3-1               “Nothing”




                  3-2
3-2

บทที่ 3

  • 1.
    3 C C Standard Output File Standard Input File 3-1 3-1 Standard Input File Buffered Standard Output File C printf Printf (“[ ”,[
  • 2.
    3–2 Output Input Output 3 -1 3–1 char - c %c short int h d %hd int - d %d long int I or L d %Ld float - f %f double - f %f long doule L f %Lf %[ 3- 2 3 -2 %d %4d 12 12 12 123 123 123 1234 1234 1234 12345 12345 12345 float %[
  • 3.
    printf(“%7.2f”,23.35000); 5 4 1 2 23.35 1. printf(“%d%c%f”,23, „z‟,4.1); 23z4.100000 2. printf(“%d %c %f”, 23. „z‟, 4.1); 23 z 4.100000 1 3. int num1 = 23; char zee = „z‟; float num2 = 4.1; printf(“%d %c %f”, num1, zee, num2); 23 z 4.100000 4. printf(“%dt%ct%5.1f”, 23, „z‟, 14.2); printf(“%dt%ct%5.1f”, 107, „A‟, 53.6); printf(“%dt%ct%5.1f”, 1754, „F‟, 122.0); printf(“%dt%ct%5.1f”, 3, „P‟, 0.1); 23 z 14.2 107 A 53.6 1754 F 122.0 3 P 0.1 5. printf(“The number is %6d”, 23);
  • 4.
    The number is 23 C Back-slash character 3-3 3-3 Back-slash character „0‟ Null Character „a‟ Alert „b‟ Backspace „t‟ Horizontal „n‟ Newline „v‟ Vertical tab „f‟ Form feed „r‟ Carriage return „‟ Single quote „”‟ Double quote „‟ Backslash 1. printf(“%d %d %dn”, 44, 55); 44 55 0 3 2 2. printf(“%d %dn”, 44, 55, 66); 44 55 2 3 3 3. long int x = 444446766; printf(“%dn”, x); -18386 Ld C scanf
  • 5.
    Scanf(“[ ”,[ 3-3 Enter Error 1. 214 156 14z scanf(“%d%d%d%c”, &a, &b, &c, %d); 14 z c scanf(“%d%d%d %c”, &a, &b, &c, %d); 2. 2314 15 2.14 scanf(“%d %d %f”, &a, &b, &c); 3. 14/26 25/66 scanf(“%2d/%2d %2d/%2d”, &num1, &num2, &num3, &num4); 4. 11-25-56 scanf(“%d-%d-%d”,&a, &b, &c); 1. int a = 0; scanf(“%d”,a); printf(“%d/n”,a);
  • 6.
    234 (Input) 0 (Output) & a error 2. float a = 2.1; scanf(“%5.2f”,&a); printf(“%5.2f”,a); 3. int a; Int b; scanf(“%d%d%d”,&a, &b); Printf(“%d %d/n”, a, b); 5 10 (Input) 5 10 (Output) 3 2 scanf 2 3 conio.h getch 1 Enter ch = getch(); getche getch ch = getch(); getchar 1 Enter
  • 7.
    ch = getchar(0; 3-1 “Nothing” 3-1 “Nothing” 3-2
  • 8.