1.

 Preprocessing Directive


 #include <stdio.h>

     stdio.h

 preprocessing directives



               2
- #include <
  >


                   include)
- #include “
  ”
2.

    main( )
                           main          “
        ”
                                     {
        }
                       {
              }          main( )
                       void main(void)
              main()
3.





            comment)

    source code
                  2
•
Run >
Run      < Ctrl + F9> )
  LampangKanlayanee School

printf( )
String)
                                           ;)
                 stdio (               standard
input output)
 #include                 directive)     stdio.h
                header file)

                    : printf()


                                     printf()

    intprintf (<control>, <argument list>);
printf()




(Statements)
 argument list
                              1
                            (,)
control                       “
”                    2

%c

%s

%   d
%   u
%   f
%   e   e

%x
%o
              1.1
    printf()

intmain( )
{ intsum=3;
printf(“ The sum is %d ”,sum);
return 0;
}

The sum is 3
          1.2
  printf()           %d     %u
intmain( )
{ intnum = -3, tot = 5;
printf(“num = %d tot = %u ”,num,tot);
return 0;
}

num = -3 tot = 5
1.3               printf()
        %f      %e              2
intmain( )
{ floatnum = 22.75;
printf(“ %.2fn%.2e ”,num,num);
return 0;
}

22.75
2.28e+01
         printf ( )

                       printf( )
    print format





    %d

    %u

    %f

    %c       1

    %s
         1





    n
    t   tab         8
    a
             Backslash


    printf( )
5 + 5 = 10

             printf( )   string format
Hello word

             3            2
              data list



    printf( )
                string format
                   ““
    data list                   ““
    printf( )

•                        d           2
•                        d           a

•                        s           b



      f)
    printf( )

                f

                     6
               printf( )         n)

printf( )
                           printf( )
         n)
printf( )
               : scanf()
intscanf (<control>, <argument list>);

    intscanf (<control>,
    <argument list>);
        scanf()
                   (key board)
argument list


      (,)
                             &
                  control

                        “”

         printf
            2.1             scanf
intmain( )
{ intnum;
scanf( “ %d ”,&num);
return 0;
}

         1
                       num
2.2                scanf
intmain( )
{ intnum; charch;
scanf( “ %c ”,&ch);
scanf( “ %d ” ,&num);
printf(“ %d %c ” ,num, ch);
return 0;
}
                                    2
                         1
                                num
                   1
                  : expression

    var = expression ;




                 var = expression ;


     var
    Expression
                  : expression

    var = expression ;




                 var = expression ;


     var
    Expression


sum = a b ;
              a
    b
        sum
                 –
      putchar()


                           putchar()

    intputchar (<character>);
            putchar()




                      (Statements)
1.4   putchar()
intmain( )
{ inta=65;
putchar(a);
putchar(„a‟);
return 0;
}

Aa
2   getchar ( )
       getchar ( )
                         1
        enter

               getchar ( );
           getchar ( );
3   getch ( )
     getch ( )
                 1

      enter

           getch ( );
4   getche ( )
     getche ( )
                  1

       enter

           getche ( );
 3.                          –

         3.1
#include <stdio.h>
intmain(){
intx_value = 9;
printf("x = %dn",x_value);
return0;
}
         3.2
#include <stdio.h>
intmain(){
intx,y,sum;
x = 7; y = 2;
sum = x + y;
printf("Total = %dn",sum);
return0;
}
         3.3
#include <stdio.h>
intmain(){
int x, y;
x = 7; y = 4;
--x; ++y;
printf("x = %2dn",x);
printf("y = %6dn",y);
return0;
}
          3.4
#include <stdio.h>
intmain(){
int profits, employees;
profits = 9; employees = 2 ;
printf("Each employee gets %.2f",
  (float) profits/employees);
return0;
}
          3.5
include<stdio.h>
intmain(){
charany_char;
printf("Please type a character: ");
  scanf("c%",&any_char);
printf("Thank you, your character are
  %c",any_char);
return0;
}
          3.6
#include <stdio.h>
int main(){
printf("n****Using .1f****n");
printf("%.1f%.1f%.1fn", 4.0, 16.5, 589.3);
printf("%.1f%.1f%.1f", 400.0, 1600.5, 58900.3);
printf("nn****Using 8.1f****n");
printf("%8.1f%8.1f%8.1fn", 4.0, 16.5, 589.3);
printf("%8.1f%8.1f%8.1f", 400.0, 1600.5, 58900.3);
printf("%-8.1f%-8.1f%-8.1fn", 4.0, 16.5, 589.3);
printf("%-8.1f%-8.1f%-8.1f", 400.0, 1600.5,
  58900.3);
return 0;
}
         3.7
#include <stdio.h>
int main(){
printf("n");
printf("xC9xCDxBBn");
printf("xC8xCDxBCn");
return 0;
}
          3.8
#include <stdio.h>
#include <ctype.h>
intmain(){
charany_char;
printf("Please type a lowercase letter:");
scanf("%c", &any_char);
if(any_char>= 'a')
printf("In uppercase: %c n",
   toupper(any_char));
return0;
}
            –

                string
          char [ n ]


    put


    puts string_argument ;
       string_argument

-
     word
Char word [15] = * Example *   ;
-
            puts
puts word ;
puts                      ;
           gets

    enter

               gets
gets          ; ;




                   string_var = get   ;


string_var = get              ;



    -
                           enter

                gets word ;
    -

 -printf   you name is %s n ,
word ;


ภาษาซี

  • 2.
    1.  Preprocessing Directive #include <stdio.h> stdio.h preprocessing directives
  • 3.
    2 - #include < > include) - #include “ ”
  • 4.
    2.  main( ) main “ ” { } { } main( ) void main(void) main()
  • 6.
    3.  comment) source code 2 •
  • 10.
    Run > Run < Ctrl + F9> ) LampangKanlayanee School printf( ) String) ;) stdio ( standard input output) #include directive) stdio.h header file)
  • 11.
    : printf() printf() intprintf (<control>, <argument list>);
  • 12.
    printf() (Statements) argument list 1 (,) control “ ” 2
  • 13.
     %c %s % d % u % f % e e %x %o
  • 14.
    1.1 printf() intmain( ) { intsum=3; printf(“ The sum is %d ”,sum); return 0; } The sum is 3
  • 15.
    1.2 printf() %d %u intmain( ) { intnum = -3, tot = 5; printf(“num = %d tot = %u ”,num,tot); return 0; } num = -3 tot = 5
  • 16.
    1.3 printf() %f %e 2 intmain( ) { floatnum = 22.75; printf(“ %.2fn%.2e ”,num,num); return 0; } 22.75 2.28e+01
  • 17.
    printf ( ) printf( ) print format
  • 18.
    %d %u %f %c 1 %s 1
  • 19.
    n t tab 8 a Backslash
  • 20.
    printf( )
  • 21.
    5 + 5= 10 printf( ) string format
  • 22.
    Hello word 3 2 data list
  • 24.
    printf( ) string format ““ data list ““ printf( ) • d 2 • d a • s b
  • 25.
    f) printf( ) f
  • 27.
    6 printf( ) n) printf( ) printf( ) n) printf( )
  • 28.
    : scanf() intscanf (<control>, <argument list>); intscanf (<control>, <argument list>); scanf() (key board)
  • 29.
    argument list (,) & control “” printf
  • 30.
    2.1 scanf intmain( ) { intnum; scanf( “ %d ”,&num); return 0; } 1 num
  • 31.
    2.2 scanf intmain( ) { intnum; charch; scanf( “ %c ”,&ch); scanf( “ %d ” ,&num); printf(“ %d %c ” ,num, ch); return 0; } 2 1 num 1
  • 32.
    : expression var = expression ; var = expression ; var Expression
  • 33.
    : expression var = expression ; var = expression ; var Expression
  • 34.
     sum = ab ; a b sum
  • 37.
    – putchar() putchar() intputchar (<character>); putchar() (Statements)
  • 38.
    1.4 putchar() intmain( ) { inta=65; putchar(a); putchar(„a‟); return 0; } Aa
  • 39.
    2 getchar ( ) getchar ( ) 1 enter getchar ( ); getchar ( );
  • 42.
    3 getch ( ) getch ( ) 1 enter getch ( );
  • 45.
    4 getche ( ) getche ( ) 1 enter getche ( );
  • 48.
     3. – 3.1 #include <stdio.h> intmain(){ intx_value = 9; printf("x = %dn",x_value); return0; }
  • 49.
    3.2 #include <stdio.h> intmain(){ intx,y,sum; x = 7; y = 2; sum = x + y; printf("Total = %dn",sum); return0; }
  • 50.
    3.3 #include <stdio.h> intmain(){ int x, y; x = 7; y = 4; --x; ++y; printf("x = %2dn",x); printf("y = %6dn",y); return0; }
  • 51.
    3.4 #include <stdio.h> intmain(){ int profits, employees; profits = 9; employees = 2 ; printf("Each employee gets %.2f", (float) profits/employees); return0; }
  • 52.
    3.5 include<stdio.h> intmain(){ charany_char; printf("Please type a character: "); scanf("c%",&any_char); printf("Thank you, your character are %c",any_char); return0; }
  • 53.
    3.6 #include <stdio.h> int main(){ printf("n****Using .1f****n"); printf("%.1f%.1f%.1fn", 4.0, 16.5, 589.3); printf("%.1f%.1f%.1f", 400.0, 1600.5, 58900.3); printf("nn****Using 8.1f****n"); printf("%8.1f%8.1f%8.1fn", 4.0, 16.5, 589.3); printf("%8.1f%8.1f%8.1f", 400.0, 1600.5, 58900.3); printf("%-8.1f%-8.1f%-8.1fn", 4.0, 16.5, 589.3); printf("%-8.1f%-8.1f%-8.1f", 400.0, 1600.5, 58900.3); return 0; }
  • 54.
    3.7 #include <stdio.h> int main(){ printf("n"); printf("xC9xCDxBBn"); printf("xC8xCDxBCn"); return 0; }
  • 55.
    3.8 #include <stdio.h> #include <ctype.h> intmain(){ charany_char; printf("Please type a lowercase letter:"); scanf("%c", &any_char); if(any_char>= 'a') printf("In uppercase: %c n", toupper(any_char)); return0; }
  • 56.
    – string char [ n ] put puts string_argument ; string_argument
  • 59.
     - word Char word [15] = * Example * ; - puts puts word ; puts ;
  • 60.
    gets enter gets gets ; ; string_var = get ; string_var = get ;
  • 63.
    - enter gets word ; - -printf you name is %s n , word ;
  • 64.