SlideShare uma empresa Scribd logo
1 de 92
Baixar para ler offline
Chapter 2
C Language Program
                             Mr.Warawut Khangkhan
                Twitter: http://twitter.com/awarawut
     Facebook: http://www.facebook.com/AjWarawut
                      E-Mail: awarawut@hotmail.com
                                Mobile: 083-0698-410
Contents

 F           C
                                   C
     F                        C
         F                    C
             C
                 C
     F (Expression)                      C

                 Mr.Warawut Khangkhan   Chapter 2 C Language Program   2
Contents (Cont.)
        F                                   C
                  F                     C




            Mr.Warawut Khangkhan   Chapter 2 C Language Program   3
Mr.Warawut Khangkhan   Chapter 2 C Language Program   4
BCPL                 B                               C
Basic Combined                                     . . 2515
Programming          PDP-7
Language             (UNIX)
                      . . 2513



                 Mr.Warawut Khangkhan   Chapter 2 C Language Program   5
F              C




    Mr.Warawut Khangkhan   Chapter 2 C Language Program   6
F               C
                (High Level Language)
      F             (OS Independent)
        F                  F (Hardware
    Independent)
              F (Structure Language)




                Mr.Warawut Khangkhan   Chapter 2 C Language Program   7
C




Mr.Warawut Khangkhan   Chapter 2 C Language Program   8
C

  ----
  ----
  ----


Source Code                                                              F
                                           F F         source code



              Mr.Warawut Khangkhan   Chapter 2 C Language Program    9
C
           F (Compiler)
    F              F                      F                           F       F
F       F F F F                                                           F
              F




                Mr.Warawut Khangkhan   Chapter 2 C Language Program               10
F

Main()
                     F
                             F               F
{

printf(“XX”);
printf(“YY”);
}




   F            F                F
                         F               F




                    Mr.Warawut Khangkhan         Chapter 2 C Language Program   11
F               F                                         C
                        F                              F       F
   F                        F F                            copy
disk                    F                         F
source code
     F        F           F                                (Binary)
       executable file (.exe)




                 Mr.Warawut Khangkhan   Chapter 2 C Language Program   12
F                                             C




    Mr.Warawut Khangkhan   Chapter 2 C Language Program   13
F                                     C
// Comment
#include <stdio.h> /* Hearder file */

… Data declarations …;

int main( ) {
     … Executable statement …;
}



             Mr.Warawut Khangkhan   Chapter 2 C Language Program   14
F                                     C
// Comment
#include <stdio.h> /* Hearder file */

… Data declarations …;

int main( ) {
     … Executable statement …;
}



             Mr.Warawut Khangkhan   Chapter 2 C Language Program   15
F                                      C
// Comment
#include <stdio.h> /* Hearder file */

… Data declarations …;
           Header File    F
int main( ) { F                F
     … Executable statement …;
}            F       F F     F F
                                                                    F
          Preprocessor Directive
              Mr.Warawut Khangkhan   Chapter 2 C Language Program       16
F                                     C
// Comment
#include <stdio.h> /* Hearder file */

… Data declarations …;                                       F
int main( ) {
     … Executable statement …;
}              data_type variable ;


              Mr.Warawut Khangkhan   Chapter 2 C Language Program   17
main   Function                      F                             F
      F                                      C
// Comment {      }
#include <stdio.h> /* Hearder file */
      function
         function main
… Data declarations …;                                             F
int main( ) {
     … Executable statement …;
}



             Mr.Warawut Khangkhan   Chapter 2 C Language Program           18
F                                             C




    Mr.Warawut Khangkhan   Chapter 2 C Language Program   19
F                                         C
          F       F   F              F           {           }

     F   (function)     F    main( )
 F            ; (semi colon)

 F        F
  F      , (comma)                                                              F
(Parameters)
    F    /* … */                                         F                F F       F
compiler

                          Mr.Warawut Khangkhan   Chapter 2 C Language Program           20
Example ex01.c
        ex01.c
#include <stdio.h> //#include “stdio.h”
#include <conio.h>

int main( ) {
   printf(“Hello World!!!”);
   getch( );

    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   21
Example ex02.c
        ex02.c
#include <stdio.h>
#include <stdlib.h>

int main( ) {
   printf(“Hello World!!!”);
   system(“PAUSE”);

    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   22
Example ex03.c
        ex03.c
#include <stdio.h>
#include <stdlib.h>

int main( ) {
   printf(“Hello “);
   printf(“World!!!”);
   printf(“n”);
   system(“PAUSE”);
    return 0;
}

                Mr.Warawut Khangkhan   Chapter 2 C Language Program   23
Example ex03.c
        ex03.c
#include <stdio.h>
#include <stdlib.h>

int main( ) {
   printf(“Hellon “);
   printf(“World!!!”);
   system(“PAUSE”);

    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   24
C




Mr.Warawut Khangkhan   Chapter 2 C Language Program   25
C
        (Variable)                                         F
F                                          F F
    F                        F                                 F               F
        F   F   F                     F          F                 F       F




                    Mr.Warawut Khangkhan    Chapter 2 C Language Program           26
C
                 (Scalar)                                                F       F
        F
              (Array)                                         F              F
    F              F
                  F (Structure)
F           F   F          F  F                        F




                   Mr.Warawut Khangkhan   Chapter 2 C Language Program               27
(Scalar)
F      2
Integer types
Real types




                Mr.Warawut Khangkhan   Chapter 2 C Language Program   28
Mr.Warawut Khangkhan   Chapter 2 C Language Program   29
Mr.Warawut Khangkhan   Chapter 2 C Language Program   30
Example limit.c
#include <stdio.h>
#include <limits.h>

int main( ) {
  printf(“Minimum char = %dn“, CHAR_MIN);
  printf(“Maximum char = %dn”, CHAR_MAX);
  printf(“Minimum int = %in”, INT_MIN);
  printf(“Maximum int = %in”, INT_MAX);
    return 0;
}
    Minimum char = -128, Maximum char = 127
    Minimum int = -32768, Maximum int = 32767

                  Mr.Warawut Khangkhan   Chapter 2 C Language Program   31
F
                         (       )
Char                         1                                 ASCII    1
                                                       0       255
Int                    2                                          –32768    32767
Short                  2                                          –32768    32767
Long                   4                                            ±
                                                                      2000
Unsigned       Unsigned short = 2                                 0    65535
               Unsigned long = 4                                  0    4000
Float                  4                                              10x    x
                                           –37         +38
Double                       8




  Mr.Warawut Khangkhan               Chapter 2 C Language Program                   32
C
F     F F             a-z              A-Z                            _
                         F               A-Z                    a-z
0-9                  _
        F         F F F                      F              F
                   F
            F                    F       F                       F




                Mr.Warawut Khangkhan   Chapter 2 C Language Program       33
C (Cont.)
     F                      (Reserved Word)
auto       break       case               char                     const
continue   default     do                 double                   else
enum       extern      float              for                      goto
if         int         long               register                 return
short      signed      sizeof             static                   struct
switch     typedef     union              unsigned                 void
volatile   while




                 Mr.Warawut Khangkhan   Chapter 2 C Language Program    34
F                                          C
  :                                  :
average     pi                 3rd_entry                     all$done
number_of_students             the end                       int
entry_total
            entryTot
   al
all_total   allTotal




              Mr.Warawut Khangkhan   Chapter 2 C Language Program   35
C
     :                              int num;
type name;                          float y;
   :                                char c;
                                    double salary;
type
name                  (                                  C)




             Mr.Warawut Khangkhan   Chapter 2 C Language Program   36
C
     :
type name = value;
   :
type
name            (            C)
value   F         F
          int num = 10;
          float y = 5.2;
          char c = ‘A’;
          double salary = 25.00;
           Mr.Warawut Khangkhan   Chapter 2 C Language Program   37
C




Mr.Warawut Khangkhan   Chapter 2 C Language Program   38
C
      (Operator)                                  F             F
                      F F             (+),             (-),         (*)
(/)                                                                   F




          Mr.Warawut Khangkhan   Chapter 2 C Language Program         39
C (Cont.)
Assignment Statement
Arithmetic Operators
Increment/Decrement Operators
Other Assignment Operators
Comparison Operators
Logical Operators



           Mr.Warawut Khangkhan   Chapter 2 C Language Program   40
Assignment Statement
  F             F     F
  F         =
     :
 variable = expression;
   :
 variable
 expression         F   F                    F


                    Mr.Warawut Khangkhan   Chapter 2 C Language Program   41
Assignment Statement (Cont.)




          Mr.Warawut Khangkhan   Chapter 2 C Language Program   42
Example term.c
#include <stdio.h>

int main( ) {
  int teerm, term_2, term_3;

    term = 3 * 5;                             term = 15
    term_2 = 2 * term;                        term_2 = 30
    term_3 = 3 * term;                        term_3 = 45


    printf("term = %dn", term);
    printf("term_2 = %dn", term_2);
    printf("term_3 = %dn", term_3);
    return 0;
}                 Mr.Warawut Khangkhan   Chapter 2 C Language Program   43
Arithmetic Operators
  F                            F F             (+),            (-),
(*)       (/)             F
      F                          F




                Mr.Warawut Khangkhan   Chapter 2 C Language Program   44
Mr.Warawut Khangkhan   Chapter 2 C Language Program   45
Example math1.c
        math1
#include <stdio.h>
                                             a+b=7
int main( ) {                                a-b=3
                                             a * b = 10
  int a = 5, b = 2, z;
  z = a + b;
  printf(“a + b = %dn”, z);
  z = a - b;
  printf(“a - b = %dn”, z);
  z = a * b;
  printf(“a * b = %dn”, z);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   46
Example math2.c
        math2
#include <stdio.h>

int main( ) {              div = 2
                           mod = 1
  int a = 5, b = 2, z;
  z = a / b;
  printf(“div = %dn”, z);
  z = a % b;
  printf(“mod = %dn”, z);
  // printf(“a %% b = %dn”, z);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   47
Increment/Decrement Operators
               /    F  1
           F       1 F                  ++
       F           1 F                 --

int i = 5, j = 4;
i++; // i = i + 1;                           “i” becomes 6
--j; // j = j – 1;                           “j” becomes 3
++i; // i = i + 1;                           “i” becomes 7

                     Mr.Warawut Khangkhan   Chapter 2 C Language Program   48
Mr.Warawut Khangkhan   Chapter 2 C Language Program   49
Example inc_dec.c
#include <stdio.h>
                                            n=       5
                                            n=       6
int main( ) {                               n=       6
  int n = 5;                                n=       7
    printf(“n = %dn”, n);
    printf(“++n = %dn”, ++n);
    printf(“n++ = %dn”, n++);
    printf(“n = %dn”, n);
    return 0;
}               Mr.Warawut Khangkhan   Chapter 2 C Language Program   50
Example effect.c
#include <stdio.h>

int main( ) {            8
  int value = 1, result;

    result = (value++ * 5) + (value++ * 3);

    printf("%dn", result);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   51
Other Assignment Operators




          Mr.Warawut Khangkhan   Chapter 2 C Language Program   52
Example other_ass.c
#include <stdio.h>

void main( ) {                              Before b = 1
                                            After b = 6
 int a = 5, b = 1;

    printf(“Before b = %dn”, b);
    b += a; // b = b + a;
    printf(“After b = %dn”, b);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   53
Comparison Operators




         Mr.Warawut Khangkhan   Chapter 2 C Language Program   54
Logical Operators




          Mr.Warawut Khangkhan   Chapter 2 C Language Program   55
Table Logical Operators
  A       B         A && B                   A || B                    !A
True    True         True                   True                      False

True    False        False                  True                      False

False   True         False                  True                      True

False   False        False                 False                      True




                Mr.Warawut Khangkhan   Chapter 2 C Language Program           56
F (EXPRESSION)
 C




 Mr.Warawut Khangkhan   Chapter 2 C Language Program   57
F (Expression)                                         C
F (Expression)          F                                         F
  F                       F                                   F
             F
      F y = 2x * 5, 2xy – 5                               F




        Mr.Warawut Khangkhan   Chapter 2 C Language Program           58
F                C (Cont.)
1.                F                       C
             F                                         C                              F
                                          F                   F
                               C
2.       F                            F
                                                        F                        F
                      F                       F                                           F
             C                    F                                                  F F
              F                           F*          x                                F/

                          Mr.Warawut Khangkhan    Chapter 2 C Language Program                59
F           C (Cont.)
3.       F                 F
                  F      F
             F        C (&&, ||, !)                                    F
      F F    F             F      F  F
        F
     c && (a <= b), (b >= c) || (c <= a)




                 Mr.Warawut Khangkhan   Chapter 2 C Language Program       60
F               C (Cont.)
4.               F
     F               F   F                                                         F
                                    F                 F                     F
         F
             a / b + 15 * c                 (a – b) * 10 / c
                   F                      F      F
                     F                                   C                             F



                             Mr.Warawut Khangkhan   Chapter 2 C Language Program           61
1                                    ()
2                          !, ++, --, (typecast)
3                                 *, /, %
4                                   +, -
5                              <, <=, >, >=

    Mr.Warawut Khangkhan   Chapter 2 C Language Program   62
(Cont.)


6                                = =, !=
7                                  &&
8                                   ||
9                          *=, /=, %=, +=, -=


    Mr.Warawut Khangkhan   Chapter 2 C Language Program   63
F
C




    Mr.Warawut Khangkhan   Chapter 2 C Language Program   64
F                                                   C
    F          F                            F             F int + float
        int – char
                                                    F      F
             F                       F
         C       F Casting                  2
◦                F
◦                F                              F




                     Mr.Warawut Khangkhan   Chapter 2 C Language Program   65
F
F                     C                       F               F
                                       F
    F F




        Mr.Warawut Khangkhan   Chapter 2 C Language Program       66
F
Var. 1     Var. 2              Var. 3
 char       int               chat -> int
  int       long              int -> long
  int    unsigned int     int -> unsigned int
  int       float            int -> float
   int      double           int -> double
 float     double          float -> double
 long      double          long -> double
double   long double    double -> long double
Example implicit.c
#include <stdio.h>

int main( ) {
  int n = 5;
  float f = 3.5, r;
                                         r = 8.500000
    r = n + f;

    printf(“r = %fn”, r);
    return 0;
}
                  Mr.Warawut Khangkhan   Chapter 2 C Language Program   68
F                                              F
       F
             F                                    F F
     :
(type)expression;
   :
type                              F
expression                             F            F


                     Mr.Warawut Khangkhan   Chapter 2 C Language Program   69
Example explicit.c
#include <stdio.h>
                                          n = 5.000000
int main( ) {                             f=3
  int n = 5;                              n+f=8
  float f = 3.2;

    printf(“n = %fn”, (float)n);
    printf(“f = %dn”, (int)f);
    printf(“n + f = %dn”, (n + (int)f));
    return 0;
}

                   Mr.Warawut Khangkhan   Chapter 2 C Language Program   70
F
C




    Mr.Warawut Khangkhan   Chapter 2 C Language Program   71
C
                 F          F        F                             F
             F       F   printf( )                           F
         F                F                                            F   F
F                                  F
     :
printf ( format, exp.1, exp.2, …);
   :
format       F   F
exp.1, exp.2         F        F

             Mr.Warawut Khangkhan   Chapter 2 C Language Program               72
C (Cont.)




Mr.Warawut Khangkhan   Chapter 2 C Language Program      73
F
%d        %i
     %u
     %0
     %x
     %f                                            (6        )
     %e                                                  E           e

               Mr.Warawut Khangkhan   Chapter 2 C Language Program       74
(Cont.)
                                         F
%c                1        (char)
%s   F                (string)
%p                       F (pointer)




         Mr.Warawut Khangkhan   Chapter 2 C Language Program   75
n                             F
t   F F      F                    1 tab ( F              6       )
r                    F cursor         F F
f   F F          F                1         F
b                         F         1

           Mr.Warawut Khangkhan    Chapter 2 C Language Program   76
Example control.c
#include <stdio.h>
                                            5                         10
int main( ) {                               15
  int a = 5, b = 10, c;

    printf(“%dt%dn”, a, b);
    c = a + b;
    printf(“%d”, c);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program        77
F      putchar(
                            putchar( )
    :
putchar (expression);
  :
expression              F                                 F
           F          ‘ ’ F ‘A’




              Mr.Warawut Khangkhan   Chapter 2 C Language Program   78
Example putchar.c
#include <stdio.h>
                           Func. printf( ) : A
int main( ) {              Func. putchar( ) : A
  char ch = ‘A’;

    printf(“Func. printf( ) : %cn”, ch);
    printf(“Func. putchar( ) : ”);
    putchar(ch);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   79
F             F      puts( )
    :
puts (expression);
  :
expression             F     F
      F          “ ” F “ABC”




              Mr.Warawut Khangkhan   Chapter 2 C Language Program   80
Example puts.c
#include <stdio.h>

int main( ) {
 char str[ ] = “ABC”;

    printf(“Func. printf( ) : %sn”, str);
    printf(“Func. puts( ) : ”);
    puts(str);
                  Func. printf( ) : ABC
    return 0;     Func. putchar( ) : ABC
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   81
F                     C
      F              F                C                          F   F
scanf( )         F                                     F
        F                F        F            FF
        (Integer),                    (Floating point),
      (Character)             F          (String)




              Mr.Warawut Khangkhan    Chapter 2 C Language Program       82
F                    C (Cont.)
      :
scanf (format, &var.1, &var.2, …);
    :
format       F   F             F
var.1, var.2         F       F          F
          &    F        F          string
  F     F          &      F



              Mr.Warawut Khangkhan   Chapter 2 C Language Program   83
F          F             F F           scanf(
                                        scanf( )
scanf(“%d %f %d”, &var1, &var2, &var3);
scanf(“%d/%f/%d”, &var1, &var2, &var3);
scanf(“%d,%f,%d”, &var1, &var2, &var3);
scanf(“%s %s %s”, var1, var2, var3);




                Mr.Warawut Khangkhan   Chapter 2 C Language Program   84
Example scanf1.c
        scanf1
#include <stdio.h>
              Input number to 2 value : 3 6
int main( ) {
              a+b=9
    int a, b, c;
    printf("Input number to 2 value : ");
    scanf("%d %d", &a, &b);
    c = a + b;
     printf("a + b = %dn", c);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   85
Example scanf2.c
        scanf2
#include <stdio.h>
                    Input number to a : 3
int main( ) {       Input number to b : 6
  int a, b, c;      a+b=9
  printf("Input number to a : ");
  scanf("%d", &a);
  printf(“Input number to b : “);
  scanf(“%d”, &b);
  c = a + b;
  printf("a + b = %dn", c);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   86
F                F      getchar(
                           getchar( )
getch(
getch( )
      :
 variable = getchar( );
 variable = getch( );
    :
 variable               F               F
 ‘ ’ F ‘A’
 getchar –     F               F 1 F (1     )                          F
 enter
 getch –     F              F 1 F (1      ) F F
 enter     F     F        F           F

                 Mr.Warawut Khangkhan   Chapter 2 C Language Program       87
Example getchar1.c
        getchar1
#include <stdio.h>

int main( ) {
  char ch1;

    printf(“Enter character 1 : “);
    scanf(“%c", &ch1);
    printf(“Result ch1 : %cn”, ch1);
    return 0;
}
                Mr.Warawut Khangkhan   Chapter 2 C Language Program   88
Example getchar2.c
        getchar2
#include <stdio.h>

int main( ) {
  char ch2, ch3;

    printf(“Enter character 2 : ”);
    ch2 = getchar( );
    printf(“Result ch2 : %cn”, ch2);
    printf(“Enter character 3 : “);
    ch3 = getch( );
    return 0;
}
                 Mr.Warawut Khangkhan   Chapter 2 C Language Program   89
F         F             F      gets( )
    :
gets (expression);
  :
expression                       F                         F
      (F   )       F                             “ ” F “ABC”




               Mr.Warawut Khangkhan   Chapter 2 C Language Program   90
Example scanf1.c
        scanf1
#include <stdio.h>

int main( ) {
  char str[ ] = “”;
    printf("Input string : ");
    scanf("%s", str);
    printf("String : %s", str);
    return 0;
}

                Mr.Warawut Khangkhan   Chapter 2 C Language Program   91
Example gets.c
#include <stdio.h>

int main( ) {
  char str[ ] = “”;
    printf(“Input string: “);
    gets(str);
    printf(“String : %s”, str);
    return 0;
}

                Mr.Warawut Khangkhan   Chapter 2 C Language Program   92

Mais conteúdo relacionado

Mais procurados

สร้างสรรค์ผลงานด้วยโปรแกรม Adobe Photoshop CS3 ที่มา http://www.skr.ac.th/~...
สร้างสรรค์ผลงานด้วยโปรแกรม  Adobe  Photoshop CS3 ที่มา http://www.skr.ac.th/~...สร้างสรรค์ผลงานด้วยโปรแกรม  Adobe  Photoshop CS3 ที่มา http://www.skr.ac.th/~...
สร้างสรรค์ผลงานด้วยโปรแกรม Adobe Photoshop CS3 ที่มา http://www.skr.ac.th/~...เชาวลักษณ์ ชาวงษ์
 
9789740333036
97897403330369789740333036
9789740333036CUPress
 
การจัดการเรียนการสอน
การจัดการเรียนการสอนการจัดการเรียนการสอน
การจัดการเรียนการสอนAnanpha Dear
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4Warawut
 
1 โลกและการเปลี่ยนแปลง
1 โลกและการเปลี่ยนแปลง1 โลกและการเปลี่ยนแปลง
1 โลกและการเปลี่ยนแปลงmuang82
 
Ch01 introduction-web
Ch01 introduction-webCh01 introduction-web
Ch01 introduction-webWarawut
 
Introduction to Computer
Introduction to ComputerIntroduction to Computer
Introduction to ComputerWarawut
 
Database Design
Database DesignDatabase Design
Database DesignWarawut
 
ใบความรู้เรื่องคำสั่ง Printf scanf
ใบความรู้เรื่องคำสั่ง Printf scanfใบความรู้เรื่องคำสั่ง Printf scanf
ใบความรู้เรื่องคำสั่ง Printf scanfธงชัย พาศรี
 
คู่มือโปรแกรม Book mark2551
คู่มือโปรแกรม Book mark2551  คู่มือโปรแกรม Book mark2551
คู่มือโปรแกรม Book mark2551 Narongchai Wanmanee
 

Mais procurados (17)

โครงสร้างภาษาซี2
โครงสร้างภาษาซี2โครงสร้างภาษาซี2
โครงสร้างภาษาซี2
 
สร้างสรรค์ผลงานด้วยโปรแกรม Adobe Photoshop CS3 ที่มา http://www.skr.ac.th/~...
สร้างสรรค์ผลงานด้วยโปรแกรม  Adobe  Photoshop CS3 ที่มา http://www.skr.ac.th/~...สร้างสรรค์ผลงานด้วยโปรแกรม  Adobe  Photoshop CS3 ที่มา http://www.skr.ac.th/~...
สร้างสรรค์ผลงานด้วยโปรแกรม Adobe Photoshop CS3 ที่มา http://www.skr.ac.th/~...
 
โครงสร้างภาษาซี1
โครงสร้างภาษาซี1โครงสร้างภาษาซี1
โครงสร้างภาษาซี1
 
9789740333036
97897403330369789740333036
9789740333036
 
การจัดการเรียนการสอน
การจัดการเรียนการสอนการจัดการเรียนการสอน
การจัดการเรียนการสอน
 
การกำหนดตัวแปร
การกำหนดตัวแปรการกำหนดตัวแปร
การกำหนดตัวแปร
 
โครงสร้างภาษาซี
โครงสร้างภาษาซีโครงสร้างภาษาซี
โครงสร้างภาษาซี
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4
 
1 โลกและการเปลี่ยนแปลง
1 โลกและการเปลี่ยนแปลง1 โลกและการเปลี่ยนแปลง
1 โลกและการเปลี่ยนแปลง
 
Ch01 introduction-web
Ch01 introduction-webCh01 introduction-web
Ch01 introduction-web
 
Introduction to Computer
Introduction to ComputerIntroduction to Computer
Introduction to Computer
 
Database Design
Database DesignDatabase Design
Database Design
 
Lms training v01-20080909
Lms training v01-20080909Lms training v01-20080909
Lms training v01-20080909
 
ใบความรู้เรื่องคำสั่ง Printf scanf
ใบความรู้เรื่องคำสั่ง Printf scanfใบความรู้เรื่องคำสั่ง Printf scanf
ใบความรู้เรื่องคำสั่ง Printf scanf
 
Profcompact
ProfcompactProfcompact
Profcompact
 
Brief create list-km090354
Brief create list-km090354Brief create list-km090354
Brief create list-km090354
 
คู่มือโปรแกรม Book mark2551
คู่มือโปรแกรม Book mark2551  คู่มือโปรแกรม Book mark2551
คู่มือโปรแกรม Book mark2551
 

Destaque

Basic C concepts.
Basic C concepts.Basic C concepts.
Basic C concepts.Farooq Mian
 
8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solvingKhan Yousafzai
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Trends, issues & concerns in school administration & supervision
Trends, issues & concerns in school administration & supervisionTrends, issues & concerns in school administration & supervision
Trends, issues & concerns in school administration & supervisionchiriter
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introductionsanthosh833
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
Concepts and principles of organization, administration, and supervision
Concepts and principles of organization, administration, and supervisionConcepts and principles of organization, administration, and supervision
Concepts and principles of organization, administration, and supervisionMalditang Maharot
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppteShikshak
 
Problems and Issues in the Philippine Educational System
Problems and Issues in the Philippine Educational SystemProblems and Issues in the Philippine Educational System
Problems and Issues in the Philippine Educational SystemJames Paglinawan
 
Administration and Supervision in Education
Administration and Supervision in EducationAdministration and Supervision in Education
Administration and Supervision in EducationCharo May Naigan
 

Destaque (17)

Basic C concepts.
Basic C concepts.Basic C concepts.
Basic C concepts.
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving8.1 alogorithm & prolem solving
8.1 alogorithm & prolem solving
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Structure in C
Structure in CStructure in C
Structure in C
 
Trends, issues & concerns in school administration & supervision
Trends, issues & concerns in school administration & supervisionTrends, issues & concerns in school administration & supervision
Trends, issues & concerns in school administration & supervision
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introduction
 
C ppt
C pptC ppt
C ppt
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
C language ppt
C language pptC language ppt
C language ppt
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Concepts and principles of organization, administration, and supervision
Concepts and principles of organization, administration, and supervisionConcepts and principles of organization, administration, and supervision
Concepts and principles of organization, administration, and supervision
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 
Problems and Issues in the Philippine Educational System
Problems and Issues in the Philippine Educational SystemProblems and Issues in the Philippine Educational System
Problems and Issues in the Philippine Educational System
 
Administration and Supervision in Education
Administration and Supervision in EducationAdministration and Supervision in Education
Administration and Supervision in Education
 

Semelhante a C Language Program

9789740333036
97897403330369789740333036
9789740333036CUPress
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2Warawut
 
การพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหา
การพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหาการพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหา
การพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหาWarawut
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3Warawut
 
Session and Cookie
Session and CookieSession and Cookie
Session and CookieWarawut
 
Upload Patch Firewall Sp3351
Upload Patch Firewall Sp3351Upload Patch Firewall Sp3351
Upload Patch Firewall Sp3351guest134db05
 

Semelhante a C Language Program (8)

9789740333036
97897403330369789740333036
9789740333036
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 
C basics
C   basicsC   basics
C basics
 
การพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหา
การพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหาการพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหา
การพัฒนาซอฟต์แวร์และวิเคราะห์การแก้ปัญหา
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3
 
Session and Cookie
Session and CookieSession and Cookie
Session and Cookie
 
Upload Patch Firewall Sp3351
Upload Patch Firewall Sp3351Upload Patch Firewall Sp3351
Upload Patch Firewall Sp3351
 
CC 3 - Module 2.pdf
CC 3 - Module 2.pdfCC 3 - Module 2.pdf
CC 3 - Module 2.pdf
 

Mais de Warawut

Database design
Database designDatabase design
Database designWarawut
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10Warawut
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9Warawut
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8Warawut
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7Warawut
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6Warawut
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6Warawut
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5Warawut
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5Warawut
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3Warawut
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2Warawut
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemWarawut
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4Warawut
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1Warawut
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MISWarawut
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3Warawut
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1Warawut
 
Upload File
Upload FileUpload File
Upload FileWarawut
 
Form Validation
Form ValidationForm Validation
Form ValidationWarawut
 

Mais de Warawut (20)

Database design
Database designDatabase design
Database design
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information System
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
 
Upload File
Upload FileUpload File
Upload File
 
Login
LoginLogin
Login
 
Form Validation
Form ValidationForm Validation
Form Validation
 

Último

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Último (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

C Language Program

  • 1. Chapter 2 C Language Program Mr.Warawut Khangkhan Twitter: http://twitter.com/awarawut Facebook: http://www.facebook.com/AjWarawut E-Mail: awarawut@hotmail.com Mobile: 083-0698-410
  • 2. Contents F C C F C F C C C F (Expression) C Mr.Warawut Khangkhan Chapter 2 C Language Program 2
  • 3. Contents (Cont.) F C F C Mr.Warawut Khangkhan Chapter 2 C Language Program 3
  • 4. Mr.Warawut Khangkhan Chapter 2 C Language Program 4
  • 5. BCPL B C Basic Combined . . 2515 Programming PDP-7 Language (UNIX) . . 2513 Mr.Warawut Khangkhan Chapter 2 C Language Program 5
  • 6. F C Mr.Warawut Khangkhan Chapter 2 C Language Program 6
  • 7. F C (High Level Language) F (OS Independent) F F (Hardware Independent) F (Structure Language) Mr.Warawut Khangkhan Chapter 2 C Language Program 7
  • 8. C Mr.Warawut Khangkhan Chapter 2 C Language Program 8
  • 9. C ---- ---- ---- Source Code F F F source code Mr.Warawut Khangkhan Chapter 2 C Language Program 9
  • 10. C F (Compiler) F F F F F F F F F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 10
  • 11. F Main() F F F { printf(“XX”); printf(“YY”); } F F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 11
  • 12. F F C F F F F F F copy disk F F source code F F F (Binary) executable file (.exe) Mr.Warawut Khangkhan Chapter 2 C Language Program 12
  • 13. F C Mr.Warawut Khangkhan Chapter 2 C Language Program 13
  • 14. F C // Comment #include <stdio.h> /* Hearder file */ … Data declarations …; int main( ) { … Executable statement …; } Mr.Warawut Khangkhan Chapter 2 C Language Program 14
  • 15. F C // Comment #include <stdio.h> /* Hearder file */ … Data declarations …; int main( ) { … Executable statement …; } Mr.Warawut Khangkhan Chapter 2 C Language Program 15
  • 16. F C // Comment #include <stdio.h> /* Hearder file */ … Data declarations …; Header File F int main( ) { F F … Executable statement …; } F F F F F F Preprocessor Directive Mr.Warawut Khangkhan Chapter 2 C Language Program 16
  • 17. F C // Comment #include <stdio.h> /* Hearder file */ … Data declarations …; F int main( ) { … Executable statement …; } data_type variable ; Mr.Warawut Khangkhan Chapter 2 C Language Program 17
  • 18. main Function F F F C // Comment { } #include <stdio.h> /* Hearder file */ function function main … Data declarations …; F int main( ) { … Executable statement …; } Mr.Warawut Khangkhan Chapter 2 C Language Program 18
  • 19. F C Mr.Warawut Khangkhan Chapter 2 C Language Program 19
  • 20. F C F F F F { } F (function) F main( ) F ; (semi colon) F F F , (comma) F (Parameters) F /* … */ F F F F compiler Mr.Warawut Khangkhan Chapter 2 C Language Program 20
  • 21. Example ex01.c ex01.c #include <stdio.h> //#include “stdio.h” #include <conio.h> int main( ) { printf(“Hello World!!!”); getch( ); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 21
  • 22. Example ex02.c ex02.c #include <stdio.h> #include <stdlib.h> int main( ) { printf(“Hello World!!!”); system(“PAUSE”); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 22
  • 23. Example ex03.c ex03.c #include <stdio.h> #include <stdlib.h> int main( ) { printf(“Hello “); printf(“World!!!”); printf(“n”); system(“PAUSE”); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 23
  • 24. Example ex03.c ex03.c #include <stdio.h> #include <stdlib.h> int main( ) { printf(“Hellon “); printf(“World!!!”); system(“PAUSE”); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 24
  • 25. C Mr.Warawut Khangkhan Chapter 2 C Language Program 25
  • 26. C (Variable) F F F F F F F F F F F F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 26
  • 27. C (Scalar) F F F (Array) F F F F F (Structure) F F F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 27
  • 28. (Scalar) F 2 Integer types Real types Mr.Warawut Khangkhan Chapter 2 C Language Program 28
  • 29. Mr.Warawut Khangkhan Chapter 2 C Language Program 29
  • 30. Mr.Warawut Khangkhan Chapter 2 C Language Program 30
  • 31. Example limit.c #include <stdio.h> #include <limits.h> int main( ) { printf(“Minimum char = %dn“, CHAR_MIN); printf(“Maximum char = %dn”, CHAR_MAX); printf(“Minimum int = %in”, INT_MIN); printf(“Maximum int = %in”, INT_MAX); return 0; } Minimum char = -128, Maximum char = 127 Minimum int = -32768, Maximum int = 32767 Mr.Warawut Khangkhan Chapter 2 C Language Program 31
  • 32. F ( ) Char 1 ASCII 1 0 255 Int 2 –32768 32767 Short 2 –32768 32767 Long 4 ± 2000 Unsigned Unsigned short = 2 0 65535 Unsigned long = 4 0 4000 Float 4 10x x –37 +38 Double 8 Mr.Warawut Khangkhan Chapter 2 C Language Program 32
  • 33. C F F F a-z A-Z _ F A-Z a-z 0-9 _ F F F F F F F F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 33
  • 34. C (Cont.) F (Reserved Word) auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while Mr.Warawut Khangkhan Chapter 2 C Language Program 34
  • 35. F C : : average pi 3rd_entry all$done number_of_students the end int entry_total entryTot al all_total allTotal Mr.Warawut Khangkhan Chapter 2 C Language Program 35
  • 36. C : int num; type name; float y; : char c; double salary; type name ( C) Mr.Warawut Khangkhan Chapter 2 C Language Program 36
  • 37. C : type name = value; : type name ( C) value F F int num = 10; float y = 5.2; char c = ‘A’; double salary = 25.00; Mr.Warawut Khangkhan Chapter 2 C Language Program 37
  • 38. C Mr.Warawut Khangkhan Chapter 2 C Language Program 38
  • 39. C (Operator) F F F F (+), (-), (*) (/) F Mr.Warawut Khangkhan Chapter 2 C Language Program 39
  • 40. C (Cont.) Assignment Statement Arithmetic Operators Increment/Decrement Operators Other Assignment Operators Comparison Operators Logical Operators Mr.Warawut Khangkhan Chapter 2 C Language Program 40
  • 41. Assignment Statement F F F F = : variable = expression; : variable expression F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 41
  • 42. Assignment Statement (Cont.) Mr.Warawut Khangkhan Chapter 2 C Language Program 42
  • 43. Example term.c #include <stdio.h> int main( ) { int teerm, term_2, term_3; term = 3 * 5; term = 15 term_2 = 2 * term; term_2 = 30 term_3 = 3 * term; term_3 = 45 printf("term = %dn", term); printf("term_2 = %dn", term_2); printf("term_3 = %dn", term_3); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 43
  • 44. Arithmetic Operators F F F (+), (-), (*) (/) F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 44
  • 45. Mr.Warawut Khangkhan Chapter 2 C Language Program 45
  • 46. Example math1.c math1 #include <stdio.h> a+b=7 int main( ) { a-b=3 a * b = 10 int a = 5, b = 2, z; z = a + b; printf(“a + b = %dn”, z); z = a - b; printf(“a - b = %dn”, z); z = a * b; printf(“a * b = %dn”, z); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 46
  • 47. Example math2.c math2 #include <stdio.h> int main( ) { div = 2 mod = 1 int a = 5, b = 2, z; z = a / b; printf(“div = %dn”, z); z = a % b; printf(“mod = %dn”, z); // printf(“a %% b = %dn”, z); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 47
  • 48. Increment/Decrement Operators / F 1 F 1 F ++ F 1 F -- int i = 5, j = 4; i++; // i = i + 1; “i” becomes 6 --j; // j = j – 1; “j” becomes 3 ++i; // i = i + 1; “i” becomes 7 Mr.Warawut Khangkhan Chapter 2 C Language Program 48
  • 49. Mr.Warawut Khangkhan Chapter 2 C Language Program 49
  • 50. Example inc_dec.c #include <stdio.h> n= 5 n= 6 int main( ) { n= 6 int n = 5; n= 7 printf(“n = %dn”, n); printf(“++n = %dn”, ++n); printf(“n++ = %dn”, n++); printf(“n = %dn”, n); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 50
  • 51. Example effect.c #include <stdio.h> int main( ) { 8 int value = 1, result; result = (value++ * 5) + (value++ * 3); printf("%dn", result); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 51
  • 52. Other Assignment Operators Mr.Warawut Khangkhan Chapter 2 C Language Program 52
  • 53. Example other_ass.c #include <stdio.h> void main( ) { Before b = 1 After b = 6 int a = 5, b = 1; printf(“Before b = %dn”, b); b += a; // b = b + a; printf(“After b = %dn”, b); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 53
  • 54. Comparison Operators Mr.Warawut Khangkhan Chapter 2 C Language Program 54
  • 55. Logical Operators Mr.Warawut Khangkhan Chapter 2 C Language Program 55
  • 56. Table Logical Operators A B A && B A || B !A True True True True False True False False True False False True False True True False False False False True Mr.Warawut Khangkhan Chapter 2 C Language Program 56
  • 57. F (EXPRESSION) C Mr.Warawut Khangkhan Chapter 2 C Language Program 57
  • 58. F (Expression) C F (Expression) F F F F F F F y = 2x * 5, 2xy – 5 F Mr.Warawut Khangkhan Chapter 2 C Language Program 58
  • 59. F C (Cont.) 1. F C F C F F F C 2. F F F F F F F C F F F F F* x F/ Mr.Warawut Khangkhan Chapter 2 C Language Program 59
  • 60. F C (Cont.) 3. F F F F F C (&&, ||, !) F F F F F F F F c && (a <= b), (b >= c) || (c <= a) Mr.Warawut Khangkhan Chapter 2 C Language Program 60
  • 61. F C (Cont.) 4. F F F F F F F F F a / b + 15 * c (a – b) * 10 / c F F F F C F Mr.Warawut Khangkhan Chapter 2 C Language Program 61
  • 62. 1 () 2 !, ++, --, (typecast) 3 *, /, % 4 +, - 5 <, <=, >, >= Mr.Warawut Khangkhan Chapter 2 C Language Program 62
  • 63. (Cont.) 6 = =, != 7 && 8 || 9 *=, /=, %=, +=, -= Mr.Warawut Khangkhan Chapter 2 C Language Program 63
  • 64. F C Mr.Warawut Khangkhan Chapter 2 C Language Program 64
  • 65. F C F F F F int + float int – char F F F F C F Casting 2 ◦ F ◦ F F Mr.Warawut Khangkhan Chapter 2 C Language Program 65
  • 66. F F C F F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 66
  • 67. F Var. 1 Var. 2 Var. 3 char int chat -> int int long int -> long int unsigned int int -> unsigned int int float int -> float int double int -> double float double float -> double long double long -> double double long double double -> long double
  • 68. Example implicit.c #include <stdio.h> int main( ) { int n = 5; float f = 3.5, r; r = 8.500000 r = n + f; printf(“r = %fn”, r); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 68
  • 69. F F F F F F : (type)expression; : type F expression F F Mr.Warawut Khangkhan Chapter 2 C Language Program 69
  • 70. Example explicit.c #include <stdio.h> n = 5.000000 int main( ) { f=3 int n = 5; n+f=8 float f = 3.2; printf(“n = %fn”, (float)n); printf(“f = %dn”, (int)f); printf(“n + f = %dn”, (n + (int)f)); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 70
  • 71. F C Mr.Warawut Khangkhan Chapter 2 C Language Program 71
  • 72. C F F F F F F printf( ) F F F F F F F : printf ( format, exp.1, exp.2, …); : format F F exp.1, exp.2 F F Mr.Warawut Khangkhan Chapter 2 C Language Program 72
  • 73. C (Cont.) Mr.Warawut Khangkhan Chapter 2 C Language Program 73
  • 74. F %d %i %u %0 %x %f (6 ) %e E e Mr.Warawut Khangkhan Chapter 2 C Language Program 74
  • 75. (Cont.) F %c 1 (char) %s F (string) %p F (pointer) Mr.Warawut Khangkhan Chapter 2 C Language Program 75
  • 76. n F t F F F 1 tab ( F 6 ) r F cursor F F f F F F 1 F b F 1 Mr.Warawut Khangkhan Chapter 2 C Language Program 76
  • 77. Example control.c #include <stdio.h> 5 10 int main( ) { 15 int a = 5, b = 10, c; printf(“%dt%dn”, a, b); c = a + b; printf(“%d”, c); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 77
  • 78. F putchar( putchar( ) : putchar (expression); : expression F F F ‘ ’ F ‘A’ Mr.Warawut Khangkhan Chapter 2 C Language Program 78
  • 79. Example putchar.c #include <stdio.h> Func. printf( ) : A int main( ) { Func. putchar( ) : A char ch = ‘A’; printf(“Func. printf( ) : %cn”, ch); printf(“Func. putchar( ) : ”); putchar(ch); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 79
  • 80. F F puts( ) : puts (expression); : expression F F F “ ” F “ABC” Mr.Warawut Khangkhan Chapter 2 C Language Program 80
  • 81. Example puts.c #include <stdio.h> int main( ) { char str[ ] = “ABC”; printf(“Func. printf( ) : %sn”, str); printf(“Func. puts( ) : ”); puts(str); Func. printf( ) : ABC return 0; Func. putchar( ) : ABC } Mr.Warawut Khangkhan Chapter 2 C Language Program 81
  • 82. F C F F C F F scanf( ) F F F F F FF (Integer), (Floating point), (Character) F (String) Mr.Warawut Khangkhan Chapter 2 C Language Program 82
  • 83. F C (Cont.) : scanf (format, &var.1, &var.2, …); : format F F F var.1, var.2 F F F & F F string F F & F Mr.Warawut Khangkhan Chapter 2 C Language Program 83
  • 84. F F F F scanf( scanf( ) scanf(“%d %f %d”, &var1, &var2, &var3); scanf(“%d/%f/%d”, &var1, &var2, &var3); scanf(“%d,%f,%d”, &var1, &var2, &var3); scanf(“%s %s %s”, var1, var2, var3); Mr.Warawut Khangkhan Chapter 2 C Language Program 84
  • 85. Example scanf1.c scanf1 #include <stdio.h> Input number to 2 value : 3 6 int main( ) { a+b=9 int a, b, c; printf("Input number to 2 value : "); scanf("%d %d", &a, &b); c = a + b; printf("a + b = %dn", c); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 85
  • 86. Example scanf2.c scanf2 #include <stdio.h> Input number to a : 3 int main( ) { Input number to b : 6 int a, b, c; a+b=9 printf("Input number to a : "); scanf("%d", &a); printf(“Input number to b : “); scanf(“%d”, &b); c = a + b; printf("a + b = %dn", c); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 86
  • 87. F F getchar( getchar( ) getch( getch( ) : variable = getchar( ); variable = getch( ); : variable F F ‘ ’ F ‘A’ getchar – F F 1 F (1 ) F enter getch – F F 1 F (1 ) F F enter F F F F Mr.Warawut Khangkhan Chapter 2 C Language Program 87
  • 88. Example getchar1.c getchar1 #include <stdio.h> int main( ) { char ch1; printf(“Enter character 1 : “); scanf(“%c", &ch1); printf(“Result ch1 : %cn”, ch1); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 88
  • 89. Example getchar2.c getchar2 #include <stdio.h> int main( ) { char ch2, ch3; printf(“Enter character 2 : ”); ch2 = getchar( ); printf(“Result ch2 : %cn”, ch2); printf(“Enter character 3 : “); ch3 = getch( ); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 89
  • 90. F F F gets( ) : gets (expression); : expression F F (F ) F “ ” F “ABC” Mr.Warawut Khangkhan Chapter 2 C Language Program 90
  • 91. Example scanf1.c scanf1 #include <stdio.h> int main( ) { char str[ ] = “”; printf("Input string : "); scanf("%s", str); printf("String : %s", str); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 91
  • 92. Example gets.c #include <stdio.h> int main( ) { char str[ ] = “”; printf(“Input string: “); gets(str); printf(“String : %s”, str); return 0; } Mr.Warawut Khangkhan Chapter 2 C Language Program 92