SlideShare a Scribd company logo
1 of 27
Download to read offline
ก

ก
ก          (standard functions)

           ก                  C        !" # $ ก% &
' header file        C ()* ก% &' # +         ,ก- *.h 0 1 )* * ก ' ก
' 2$ * 3&0 ก " * 30' header file ' 2 ก " 2! (0* '
(4 , #include<header file.h>         ' ,0& *        * 6 #ก 2! 2$, 7'
   ก     *ก      8! ก                ก            3   C compiler     !"
 9)*': 3' 4 0& ' ก      6 #ก 4 ':ก          6 #ก ,$ &ก# $ 0 !"    ("
* 22$ ก ก           &0 ;        ก ; (library functions)
ก              ก pow(x,y)      ก
       กก ! xy "          # x $ # y     % #& double '(
     ก pow(x,y) )$*+ก ก,-. header file      math.h     / )(
          #include<math.h>     ก +        ! "# ก
     ก main )( )$     * ก ก pow(x,y)          1 "# ก
/.
ก            (mathematic functions)
     ก    ' ,4 : ก (4 &< (< = , # $ก0* 2$' ก       $ " 2$ *
' (4 , #include <math.h> # ก* 30 *      * 6 #ก # $ &# 2$'
  ก     $ "2$ *       (type)    double )* 2 ก 9> 2 ก ก
  $ "2$ (0 ,0 ก * * 3        double 0 ก
 ก                   ! " #

acos(x)            asin(x)            atan(x)
sin(x)             cos(x)             tan(x)
sqrt(x)             exp(x)            pow(x,y)
log(x)              log10(x)         ceil(x)
floor(x)            fabs(x)
1) ก acos(x)       ก               ' (4 &<: (0 arc cosine * x 6                  x   (0
 - ' : 0& (radian)                      acos(x);

2)   ก    asin(x) #&     ก              2         arc sine !      x "      x #&
 3                                 asin(x);
3)   ก    atan(x) #&         ก              2      arc tan !      x "      x #&
 3                               atan(x);
4)   ก    sin(x) #&       ก                 2     sine !    x "     x #&         3
                       sin(x);

 5) ก       cos(x) #&              ก              2     cosine !           x "
   x #&      3                                  cos(x);
6)   ก    tan(x) #&      ก              2         tan !    x "     x #&      3
                         tan(x);
ก          7.1 #, ก '                 ก     acos(x), asin(x), atan(x), sin(x),
cos(x) # $ tan(x)

                               /*        math1.c            */
        #include<stdio.h>                                                  /*              1 */
        #include<math.h>                                                   /*              2 */
        #include<conio.h>                                                  /*              3 */
       void main(void)                                                      /*              4 */
                    {                                          /*          5 */
               double r, pi = 3.141592654;                            /*               6 */
              r = pi/180;                                             /*                7 */
              clrscr();                                               /*               8 */
             printf("%fn",asin(r));                                   /*                9 */
             printf("%fn",acos(r));                                   /*               10 */
            printf("%fn",atan(r));                                    /*                11 */
            printf("%fn",sin(r));                                     /*                12 */
             printf("%fn",cos(r));                                    /*               13 */
            printf("%fn",tan(r));                                     /*                14 */
                  printf("nPress any key back to program ..."); /*            15 */
              getch();                                                /*               16 */
                  }                                           /*           17 */
ก!   ก"
#$ % & '!   ก"

! " 9 (4 , printf("%fn",asin(r)); ก (4 &<: (0 arc
sin * &# r 6 r          - ' : 0&      # $#,     9> **ก2* 9
      10 (4 , printf("%fn",acos(r));     ก (4 &<: (0 arc
cosine * &# r 6 r            - ' : 0&     # $#,   9> **ก
2* 9
! " 11 (4 , printf("%fn",atan(r)); ก (4 &<: (0 arc
tan * &# r 6 r           - ' : 0&     # $#,     9> **ก2* 9
! " 12 (4 , printf("%fn",sin(r)); ก (4 &<: (0 sine * &
# r6 r         - ' : 0&       # $#,    9> **ก2* 9
! " 13 (4 , printf("%fn",cos(r)); ก (4 &<:
(0 cosine * &# r 6 r           - ' : 0&     # $#,   9>
   **ก2* 9
! " 14 (4 , printf("%fn",tan(r)); ก (4 &<:
(0 tan * &# r 6 r       - ' : 0&        # $#,     9> **ก
2* 9
! " 15 16 9 9 *(& ':ก ( ' 1 9)*ก ,306 #ก # $: - *
   (0 ' 1 0 ก enter 2$ก    ,306 #ก
7) ก    sqrt(x)
        ก ' : (0 ก 2 (square root) * (0 ( : )* &#   x 6
  x 2$ * (0 (    & : )* &#    (0 0
3 # sqrt(x);
8)   ก exp(x)
     #& ก          ex "   x #&         # )$ #&      ก
ก ! e "        e    # $ 2 2.718282
 +# -- exp(x);
9) ก pow(x,y)
 #& ก           xy "
 +# -- pow(x, y);
!   ก "*+%',              7.2
    ก             ก       sqrt(x), exp(x)              $ pow(x, y)
                                  /*         math2.c */
        #include<stdio.h>                                                   /*
                                              1 */
        #include<math.h>                                                    /*
                                              2 */
        #include<conio.h>                                                  /*
                                              3 */
        void main(void)                                                     /*
                                              4 */
                {                                            /*       5 */
           double x = 2.5, y = 7.0, z = 21.5;                    /*             6 */
           clrscr( );                                            /*             7 */
          printf("%.4fn",pow(x,y));                              /*              8 */
          printf("%.4fn",sqrt(z));                               /*              9 */
             printf("%.4fn",exp(y));                                 /*
                                            10 */
               printf("nPress any key back to program ..."); /*          11 */
          getch();                                               /*             12 */
                 }                                        /*        13 */
ก!   ก"
#$ % & '!     ก"
) ก"# ก          7.2   * 9%- ก    ! "# ก    :; .     /
           8     printf("%.4fn",pow(x,y)); ก     2
xy "      x #&             #      '( )$     กก <+   $
y #&              #     #&   กก      $  = . ก) 1 >
           9   printf("%.4fn",sqrt(z)); ก       2
      ก   (square root) !            # z"   z )$
 #&        %   !       #    . % - $      = . )1>
         10      printf("%.4fn",exp(y)); ก      2
     ey " y #&             # )$ #&     กก ! e "
    e    # $ 2 2.718282 $      = . ก) 1 >
            11 1 12 >% >!      ก    ;>ก - +
 "# ก         $ 3 -     ;    ก enter )$ก - ! +"# ก
10)   ก      log(x)
           #& ก         log    n (natural logarithm) !
              # x "   x #&          #      #& -. .
          log(x);
11)    ก   log10(x)
      ก         log     10 !           # x "    x #&
            #     #& -. .
        log10(x);

12)    กceil(x)
  #& ก        ก # <A < % !(/ !     # x * x #&       !
)   < %     * x #& !)        , )$. ก # <A < %
     ceil(x);
13)     ก      floor(x)
   #&       ก       ก   <A < % %/ !     # x * x #&   !)
 < %          * x #& !)      , )$. ก     <A < % %/
            floor(x);

 14. ก         fabs(x)
   #& ก                 -+ 2 (absolute value) !
  # x "         x #&             # ก,-     !)3 < %   -ก
  -ก,.            fabs(x);
ก    +   2      ,%'3
1) ก clrscr( )
 #& ก         ก -! +     ก) ก) 1 > -- text mode
 +# -- clrscr( );
2) ก gotoxy(x,y)
 #& ก               /     (cursor)    .#          $-3. - ) 1 >
+# -- gotoxy(x,y );

3) ก clreol( )
  #& ก       -!     -       cursor     +"   -!    * )ก
       ! cursor .#) ก $ )--
 +# -- clreol( );
4)        กdeline( )
   #& ก        -!             /-        cursor        + ) ก / ก,     !
-        +!    !(/
 +# -- deline( );
   5) ก insline( )
   #& ก          ก-                1-   "        ก + -             cursor   +
 +# -- insline( );
     6)   ก sizeof(x)
         #& ก        ) -! !      # x              !      ก Byte
     +# -- sizeof(x); sizeof(type);
     7)       ก   system( )
        #& ก            * ก       +         MS-DOS                   .
      +# -- system(“dos-command”);
8) ก abort( )
   #& ก        ก %กก     ! "# ก "        .      )$        ,)
     .   $)$ !      - ก BAbnormal program
termination”           ก )1>
 +# -- abort( );

 9)   ก   abs(x)
    #& ก           -+ 2!   x "   x #&   # ก,-    !)   ,        /
  +# -- abs(x);

*+%',         ก    ก
atoi( ) char numstr[20] = “1000”; int d;d =atoi(numstr);
printf (“%d”, d); = >9 .       ! 1000
!   ก "*+%',                ก               ก       atoi( ), atof( )                       $ atol( )

                                /*      atoifl.c            */
       #include<stdio.h>                                                    /*              1 */
       #include<stdlib.h>                                                   /*              2 */
       #include<conio.h>                                                    /*              3 */
      void main(void)                                                        /*              4 */
                   {                                           /*            5 */
             char s1[5] = "123";                                       /*                6 */
             char s2[10] = "14.573";                                   /*                7 */
              char s3[15] = "1234567891";                              /*                8 */
             int as1; float fs2; long ls3;                             /*                9 */
             clrscr( );                                               /*                10 */
            as1 = 2 * atoi(s1);                                       /*                11 */
            fs2 = 2 * atof(s2);                                       /*                12 */
             ls3 = atol(s3);                                          /*                13 */
            printf("AS1 = %dn",as1);                                  /*                14 */
            printf("FS2 = %fn",fs2);                                  /*                15 */
            printf("LS3 = %ldn",ls3);                                /*                16 */
                  printf("nPress any key back to program ..."); /*             17 */
            getch();                                                  /*                18 */
                   }                                          /*            19 */
ก!   ก"
#$ % & '!   ก"

        11       ก atoi( ) #           % s1 #&      !)         ,
     * .#      2. '(        /)$ +2ก- ! 2 ก,-.      # as1
        12       ก atof( ) #            % s2 #&      ! < %
     * .#      2. '(       /)$ +2ก- ! 2 ก,-.       # fs2
        13       ก atol( ) #          % s3 #&       !)       ,
  % long integer ก,-.      # ls3
        14 45 16      !        # as1, fs2 $ as3            -
    = . ก) 1 >
        17 1 18 >% >!           ก    ; > ก - +"# ก      $ 3
-     ;      ก enter )$ก - ! +"# ก
6 #ก     0*

# $" ! ก "# ก
    -     *    #& 3      ก,-. Library
    - "# ก          > ก-     '/ ;ก > $: &
     ' ก     6 #ก
    - 0 0*ก #ก (Debug) $ Maintain6 #  #ก
    - 0 0*ก **ก# 6 #ก # Top-Down Design
Top-Down Design
  ก ก --"# ก    ก               :   $ --   $ ก
ก        $ -      ก )           )


"# ก     *-ก           . 3" +
1. " +   2 )
2. " +   21 A
3. " +   2 )    3 9%
!   ก "',%'

      "# ก
    # $ก <

PROCEDURE or                      6,+ 7% !   ก "',%'
FUNCTION
BEGIN
   statement (s);
end;
!   ก "',%'

-6 #ก 0* & : ,0& $ก = &# ก0* BEGIN *
6 #ก : ก
-6 #ก 0* ,0& :& ,0& $ก = # $ ,0& (4 , 6 #ก : ก
# ก 0
      -,0& :& !"  & PROCEDURE : )* FUNCTION
           2 & END; # END.
-6 #ก 0* 4       * 0 * 73ก ก6 6 #ก : ก
! 89 %          1 ก
"# ก           1A#         2 --
   -"> '
   - ก
!    ก     $    "> '       $ ก
                ก                           ! 89 %
     : )* ก &# : )* 92            -
    2! , 7'                             (    ,)   )(
      -ก4 : (0 ': &#              ก -
      -          (0
      -9 9(0 9> * ก
ก          $ 96 %
        6" &ก
6 + :* & ,+" 9 7 15
6 + &*       "; 6+6 &< 9 7 18
6 + 6=+   9">% ก 9 7 19
6 + &*' #= 9#' 9 7 31
6 + ก " ? ? *, '7$ 9 7 37
6 + & +@ 6 = %', 9 7 38
6 + +&6      =9 AB%? 9 7 39
 ก9 ' C " '"?5กA D 6/2

More Related Content

Viewers also liked

Viewers also liked (18)

Ministerio Ciencia Y Tecnologia Jornadas I+D+I
Ministerio Ciencia Y Tecnologia   Jornadas I+D+IMinisterio Ciencia Y Tecnologia   Jornadas I+D+I
Ministerio Ciencia Y Tecnologia Jornadas I+D+I
 
Agapea Jornadas I+D+I
Agapea   Jornadas I+D+IAgapea   Jornadas I+D+I
Agapea Jornadas I+D+I
 
RIVISTA DEI GIOVANI MEDICI NUM. 1
RIVISTA DEI GIOVANI MEDICI NUM. 1RIVISTA DEI GIOVANI MEDICI NUM. 1
RIVISTA DEI GIOVANI MEDICI NUM. 1
 
Lietuva Brangi
Lietuva BrangiLietuva Brangi
Lietuva Brangi
 
Amq La Vetta Condivisa Def
Amq La Vetta Condivisa DefAmq La Vetta Condivisa Def
Amq La Vetta Condivisa Def
 
Lezione Form
Lezione FormLezione Form
Lezione Form
 
Ricercamaster.It 09
Ricercamaster.It 09Ricercamaster.It 09
Ricercamaster.It 09
 
Ephlux Corporate Profile
Ephlux Corporate ProfileEphlux Corporate Profile
Ephlux Corporate Profile
 
Magee Dday2 Fixing App Performance Italiano
Magee Dday2 Fixing App Performance ItalianoMagee Dday2 Fixing App Performance Italiano
Magee Dday2 Fixing App Performance Italiano
 
Il manifesto dei 500
Il manifesto dei 500Il manifesto dei 500
Il manifesto dei 500
 
Armando tu Estrategia de Internet
Armando tu Estrategia de InternetArmando tu Estrategia de Internet
Armando tu Estrategia de Internet
 
Ict
IctIct
Ict
 
La soluzione ai problemi di mobilità urbana - Giacomo Biraghi
La soluzione ai problemi di mobilità urbana - Giacomo BiraghiLa soluzione ai problemi di mobilità urbana - Giacomo Biraghi
La soluzione ai problemi di mobilità urbana - Giacomo Biraghi
 
Alcance de proyectos
Alcance de proyectosAlcance de proyectos
Alcance de proyectos
 
Mobile Ip v.1
Mobile Ip v.1Mobile Ip v.1
Mobile Ip v.1
 
IL RISCHIO PRIVACY E I PRESIDI AZIENDALI DI CONTROLLO
IL RISCHIO PRIVACY E I PRESIDI AZIENDALI DI CONTROLLOIL RISCHIO PRIVACY E I PRESIDI AZIENDALI DI CONTROLLO
IL RISCHIO PRIVACY E I PRESIDI AZIENDALI DI CONTROLLO
 
Terra2012 modulo1 csa
Terra2012 modulo1 csaTerra2012 modulo1 csa
Terra2012 modulo1 csa
 
Privacy e riservatezza nella consulenza tecnica (estratto)
Privacy e riservatezza nella consulenza tecnica (estratto)Privacy e riservatezza nella consulenza tecnica (estratto)
Privacy e riservatezza nella consulenza tecnica (estratto)
 

Similar to โปรแกรมย่อยและฟังก์ชันมาตรฐาน

หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์
หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์
หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์ครูสุวีร์ดา ริจนา
 
บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3
บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3
บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3yana54
 
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptxMicrosoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptxFinian Nian
 
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptxMicrosoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptxFinian Nian
 
โปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyard
โปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyardโปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyard
โปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart ShipyardKittipoom Poomkokruk
 
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1page
ใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1pageใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1page
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1pagePrachoom Rangkasikorn
 
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4page
ใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4pageใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4page
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4pagePrachoom Rangkasikorn
 
หลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้น
หลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้นหลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้น
หลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้นสุรินทร์ ดีแก้วเกษ
 
Information technology
Information technologyInformation technology
Information technologychukiat008
 
บทเรียนสำเร็จรูปไม้คลุมดิน4
บทเรียนสำเร็จรูปไม้คลุมดิน4บทเรียนสำเร็จรูปไม้คลุมดิน4
บทเรียนสำเร็จรูปไม้คลุมดิน4yana54
 
แนวข้อสอบกรมพัฒนาฝีมือแรงงาน
แนวข้อสอบกรมพัฒนาฝีมือแรงงานแนวข้อสอบกรมพัฒนาฝีมือแรงงาน
แนวข้อสอบกรมพัฒนาฝีมือแรงงานเดโช พระกาย
 
Hardware and data information
Hardware and data informationHardware and data information
Hardware and data informationchukiat008
 
ฟังก์ชันในภาษา
ฟังก์ชันในภาษาฟังก์ชันในภาษา
ฟังก์ชันในภาษาSedthawoot Pitapo
 

Similar to โปรแกรมย่อยและฟังก์ชันมาตรฐาน (20)

หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์
หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์
หนังสือคู่มือมัคนายกน้อย ... ครูชิตชัย อุ่นอกพันธ์
 
บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3
บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3
บทเรียนสำเร็จรูปเรื่องไม้พุ่ม3
 
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptxMicrosoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
 
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptxMicrosoft power point   วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
Microsoft power point วิธีการเชิงวัตถุและการออกแบบคลาส.pptx
 
Photoscape
PhotoscapePhotoscape
Photoscape
 
โปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyard
โปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyardโปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyard
โปรแกรมคอมพิวเตอร์ช่วยบริหารงานอู่เรือ Smart Shipyard
 
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1page
ใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1pageใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1page
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-1page
 
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4page
ใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4pageใบความรู้  บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4page
ใบความรู้ บทบาทหน้าที่ของท้องถิ่นและรัฐบาล+496+dltvsocp6+54soc p06 f12-4page
 
หลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้น
หลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้นหลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้น
หลักการวิเคราะห์ผลิตภัณฑ์เบื้องต้น
 
Information technology
Information technologyInformation technology
Information technology
 
บทเรียนสำเร็จรูปไม้คลุมดิน4
บทเรียนสำเร็จรูปไม้คลุมดิน4บทเรียนสำเร็จรูปไม้คลุมดิน4
บทเรียนสำเร็จรูปไม้คลุมดิน4
 
Presentation haccp
Presentation haccpPresentation haccp
Presentation haccp
 
แนวข้อสอบกรมพัฒนาฝีมือแรงงาน
แนวข้อสอบกรมพัฒนาฝีมือแรงงานแนวข้อสอบกรมพัฒนาฝีมือแรงงาน
แนวข้อสอบกรมพัฒนาฝีมือแรงงาน
 
Intro
IntroIntro
Intro
 
Hardware and data information
Hardware and data informationHardware and data information
Hardware and data information
 
จาวา1
จาวา1จาวา1
จาวา1
 
Pasa
PasaPasa
Pasa
 
Thai lang.
Thai lang.Thai lang.
Thai lang.
 
ฟังก์ชันในภาษา
ฟังก์ชันในภาษาฟังก์ชันในภาษา
ฟังก์ชันในภาษา
 
การจัดการเอกสาร
การจัดการเอกสารการจัดการเอกสาร
การจัดการเอกสาร
 

โปรแกรมย่อยและฟังก์ชันมาตรฐาน

  • 2. (standard functions) ก C !" # $ ก% & ' header file C ()* ก% &' # + ,ก- *.h 0 1 )* * ก ' ก ' 2$ * 3&0 ก " * 30' header file ' 2 ก " 2! (0* ' (4 , #include<header file.h> ' ,0& * * 6 #ก 2! 2$, 7' ก *ก 8! ก ก 3 C compiler !" 9)*': 3' 4 0& ' ก 6 #ก 4 ':ก 6 #ก ,$ &ก# $ 0 !" (" * 22$ ก ก &0 ; ก ; (library functions)
  • 3. ก pow(x,y) ก กก ! xy " # x $ # y % #& double '( ก pow(x,y) )$*+ก ก,-. header file math.h / )( #include<math.h> ก + ! "# ก ก main )( )$ * ก ก pow(x,y) 1 "# ก /.
  • 4. (mathematic functions) ก ' ,4 : ก (4 &< (< = , # $ก0* 2$' ก $ " 2$ * ' (4 , #include <math.h> # ก* 30 * * 6 #ก # $ &# 2$' ก $ "2$ * (type) double )* 2 ก 9> 2 ก ก $ "2$ (0 ,0 ก * * 3 double 0 ก ก ! " # acos(x) asin(x) atan(x) sin(x) cos(x) tan(x) sqrt(x) exp(x) pow(x,y) log(x) log10(x) ceil(x) floor(x) fabs(x)
  • 5. 1) ก acos(x) ก ' (4 &<: (0 arc cosine * x 6 x (0 - ' : 0& (radian) acos(x); 2) ก asin(x) #& ก 2 arc sine ! x " x #& 3 asin(x); 3) ก atan(x) #& ก 2 arc tan ! x " x #& 3 atan(x); 4) ก sin(x) #& ก 2 sine ! x " x #& 3 sin(x); 5) ก cos(x) #& ก 2 cosine ! x " x #& 3 cos(x); 6) ก tan(x) #& ก 2 tan ! x " x #& 3 tan(x);
  • 6. 7.1 #, ก ' ก acos(x), asin(x), atan(x), sin(x), cos(x) # $ tan(x) /* math1.c */ #include<stdio.h> /* 1 */ #include<math.h> /* 2 */ #include<conio.h> /* 3 */ void main(void) /* 4 */ { /* 5 */ double r, pi = 3.141592654; /* 6 */ r = pi/180; /* 7 */ clrscr(); /* 8 */ printf("%fn",asin(r)); /* 9 */ printf("%fn",acos(r)); /* 10 */ printf("%fn",atan(r)); /* 11 */ printf("%fn",sin(r)); /* 12 */ printf("%fn",cos(r)); /* 13 */ printf("%fn",tan(r)); /* 14 */ printf("nPress any key back to program ..."); /* 15 */ getch(); /* 16 */ } /* 17 */
  • 7. ก! ก"
  • 8. #$ % & '! ก" ! " 9 (4 , printf("%fn",asin(r)); ก (4 &<: (0 arc sin * &# r 6 r - ' : 0& # $#, 9> **ก2* 9 10 (4 , printf("%fn",acos(r)); ก (4 &<: (0 arc cosine * &# r 6 r - ' : 0& # $#, 9> **ก 2* 9 ! " 11 (4 , printf("%fn",atan(r)); ก (4 &<: (0 arc tan * &# r 6 r - ' : 0& # $#, 9> **ก2* 9 ! " 12 (4 , printf("%fn",sin(r)); ก (4 &<: (0 sine * & # r6 r - ' : 0& # $#, 9> **ก2* 9
  • 9. ! " 13 (4 , printf("%fn",cos(r)); ก (4 &<: (0 cosine * &# r 6 r - ' : 0& # $#, 9> **ก2* 9 ! " 14 (4 , printf("%fn",tan(r)); ก (4 &<: (0 tan * &# r 6 r - ' : 0& # $#, 9> **ก 2* 9 ! " 15 16 9 9 *(& ':ก ( ' 1 9)*ก ,306 #ก # $: - * (0 ' 1 0 ก enter 2$ก ,306 #ก
  • 10. 7) ก sqrt(x) ก ' : (0 ก 2 (square root) * (0 ( : )* &# x 6 x 2$ * (0 ( & : )* &# (0 0 3 # sqrt(x); 8) ก exp(x) #& ก ex " x #& # )$ #& ก ก ! e " e # $ 2 2.718282 +# -- exp(x); 9) ก pow(x,y) #& ก xy " +# -- pow(x, y);
  • 11. ! ก "*+%', 7.2 ก ก sqrt(x), exp(x) $ pow(x, y) /* math2.c */ #include<stdio.h> /* 1 */ #include<math.h> /* 2 */ #include<conio.h> /* 3 */ void main(void) /* 4 */ { /* 5 */ double x = 2.5, y = 7.0, z = 21.5; /* 6 */ clrscr( ); /* 7 */ printf("%.4fn",pow(x,y)); /* 8 */ printf("%.4fn",sqrt(z)); /* 9 */ printf("%.4fn",exp(y)); /* 10 */ printf("nPress any key back to program ..."); /* 11 */ getch(); /* 12 */ } /* 13 */
  • 12. ก! ก"
  • 13. #$ % & '! ก" ) ก"# ก 7.2 * 9%- ก ! "# ก :; . / 8 printf("%.4fn",pow(x,y)); ก 2 xy " x #& # '( )$ กก <+ $ y #& # #& กก $ = . ก) 1 > 9 printf("%.4fn",sqrt(z)); ก 2 ก (square root) ! # z" z )$ #& % ! # . % - $ = . )1> 10 printf("%.4fn",exp(y)); ก 2 ey " y #& # )$ #& กก ! e " e # $ 2 2.718282 $ = . ก) 1 > 11 1 12 >% >! ก ;>ก - + "# ก $ 3 - ; ก enter )$ก - ! +"# ก
  • 14. 10) ก log(x) #& ก log n (natural logarithm) ! # x " x #& # #& -. . log(x); 11) ก log10(x) ก log 10 ! # x " x #& # #& -. . log10(x); 12) กceil(x) #& ก ก # <A < % !(/ ! # x * x #& ! ) < % * x #& !) , )$. ก # <A < % ceil(x);
  • 15. 13) ก floor(x) #& ก ก <A < % %/ ! # x * x #& !) < % * x #& !) , )$. ก <A < % %/ floor(x); 14. ก fabs(x) #& ก -+ 2 (absolute value) ! # x " x #& # ก,- !)3 < % -ก -ก,. fabs(x);
  • 16. + 2 ,%'3 1) ก clrscr( ) #& ก ก -! + ก) ก) 1 > -- text mode +# -- clrscr( ); 2) ก gotoxy(x,y) #& ก / (cursor) .# $-3. - ) 1 > +# -- gotoxy(x,y ); 3) ก clreol( ) #& ก -! - cursor +" -! * )ก ! cursor .#) ก $ )-- +# -- clreol( );
  • 17. 4) กdeline( ) #& ก -! /- cursor + ) ก / ก, ! - +! !(/ +# -- deline( ); 5) ก insline( ) #& ก ก- 1- " ก + - cursor + +# -- insline( ); 6) ก sizeof(x) #& ก ) -! ! # x ! ก Byte +# -- sizeof(x); sizeof(type); 7) ก system( ) #& ก * ก + MS-DOS . +# -- system(“dos-command”);
  • 18. 8) ก abort( ) #& ก ก %กก ! "# ก " . )$ ,) . $)$ ! - ก BAbnormal program termination” ก )1> +# -- abort( ); 9) ก abs(x) #& ก -+ 2! x " x #& # ก,- !) , / +# -- abs(x); *+%', ก ก atoi( ) char numstr[20] = “1000”; int d;d =atoi(numstr); printf (“%d”, d); = >9 . ! 1000
  • 19. ! ก "*+%', ก ก atoi( ), atof( ) $ atol( ) /* atoifl.c */ #include<stdio.h> /* 1 */ #include<stdlib.h> /* 2 */ #include<conio.h> /* 3 */ void main(void) /* 4 */ { /* 5 */ char s1[5] = "123"; /* 6 */ char s2[10] = "14.573"; /* 7 */ char s3[15] = "1234567891"; /* 8 */ int as1; float fs2; long ls3; /* 9 */ clrscr( ); /* 10 */ as1 = 2 * atoi(s1); /* 11 */ fs2 = 2 * atof(s2); /* 12 */ ls3 = atol(s3); /* 13 */ printf("AS1 = %dn",as1); /* 14 */ printf("FS2 = %fn",fs2); /* 15 */ printf("LS3 = %ldn",ls3); /* 16 */ printf("nPress any key back to program ..."); /* 17 */ getch(); /* 18 */ } /* 19 */
  • 20. ก! ก"
  • 21. #$ % & '! ก" 11 ก atoi( ) # % s1 #& !) , * .# 2. '( /)$ +2ก- ! 2 ก,-. # as1 12 ก atof( ) # % s2 #& ! < % * .# 2. '( /)$ +2ก- ! 2 ก,-. # fs2 13 ก atol( ) # % s3 #& !) , % long integer ก,-. # ls3 14 45 16 ! # as1, fs2 $ as3 - = . ก) 1 > 17 1 18 >% >! ก ; > ก - +"# ก $ 3 - ; ก enter )$ก - ! +"# ก
  • 22. 6 #ก 0* # $" ! ก "# ก - * #& 3 ก,-. Library - "# ก > ก- '/ ;ก > $: & ' ก 6 #ก - 0 0*ก #ก (Debug) $ Maintain6 # #ก - 0 0*ก **ก# 6 #ก # Top-Down Design
  • 23. Top-Down Design ก ก --"# ก ก : $ -- $ ก ก $ - ก ) ) "# ก *-ก . 3" + 1. " + 2 ) 2. " + 21 A 3. " + 2 ) 3 9%
  • 24. ! ก "',%' "# ก # $ก < PROCEDURE or 6,+ 7% ! ก "',%' FUNCTION BEGIN statement (s); end;
  • 25. ! ก "',%' -6 #ก 0* & : ,0& $ก = &# ก0* BEGIN * 6 #ก : ก -6 #ก 0* ,0& :& ,0& $ก = # $ ,0& (4 , 6 #ก : ก # ก 0 -,0& :& !" & PROCEDURE : )* FUNCTION 2 & END; # END. -6 #ก 0* 4 * 0 * 73ก ก6 6 #ก : ก
  • 26. ! 89 % 1 ก "# ก 1A# 2 -- -"> ' - ก ! ก $ "> ' $ ก ก ! 89 % : )* ก &# : )* 92 - 2! , 7' ( ,) )( -ก4 : (0 ': &# ก - - (0 -9 9(0 9> * ก
  • 27. $ 96 % 6" &ก 6 + :* & ,+" 9 7 15 6 + &* "; 6+6 &< 9 7 18 6 + 6=+ 9">% ก 9 7 19 6 + &*' #= 9#' 9 7 31 6 + ก " ? ? *, '7$ 9 7 37 6 + & +@ 6 = %', 9 7 38 6 + +&6 =9 AB%? 9 7 39 ก9 ' C " '"?5กA D 6/2