SlideShare une entreprise Scribd logo
1  sur  63
• Dev-C++:

•
•
•
•
•

             2
Dev-C++
•
    File > New > Source File


•


•                         .c
        first.c
                                 3
Dev-C++
•
    

       F9
•                  :
        getch()




                                 4
main
                                                         stdio.h
                  #include <stdio.h>

            int   int main()
                  {
                    int a, b, sum;
printf()            printf("Enter A: ");          int
                    scanf("%d", &a);           a, b       sum
                    printf("Enter B: ");
                    scanf("%d", &b);           scanf()
                    sum = a+b;
                    printf("Sum = %dn", sum);
                    getch();
                    return 0;
                  }
                                  0
                                                           ;

                                                                   5
(Comment)
•


•   /*   …
             (        )… */
    //   …
                 (    )…
         /* arithmetic
                 expression */
         // create                 6
a
(Beep)
  n                 (newline)
         backslash


  ’
                                 7
(address) (data)
   0000     32     1   =1   8
   0001     67
   0002    255
   0003      0
   0004    121
     :       :



                            8
(       )
char         1                 -128              +127

short        2             -32,768            +32,767

int
         2            -32,768    -        +32,767
             4       2,147,483,648     +2,147,483,647

long         4       -2,147,483,648    +2,147,483,647

float        4           3.4 * 10-38        3.4 * 1038

double       8          1.7 * 10-308       1.7 * 10-308
                                                          9
(Variable)
•

                                         (               )
                                    :          :
            short a, b, sum;       1000       10
                                               2    a
            a = 10;                1001       30
                                               0
            b = 5;                 1002       211
                                               5    b
            sum = a+b;             1003       0
                                              5
                                   1004       15
                                               8    sum
                                   1005       23
                                               0
                                    :          :
        b         5            )
        &b         1002
                                                              10
(Variable)

               underscore ( _ )

               underscore ( _ )
            1-32
                                 $
   Case sensitive

    Reserve words                     11
C
auto      double        int      struct
break     else          long     switch
case      enum          register typedef
char      extern        return   union
const     float         short    unsigned
continue for            signed   void
default   goto sizeof   while    do
                                            12
type variable-list   [=value] ;

• variable-list




               (,)
     type
     value                                     13
int a=1;
int lower;
float      man,ratio;
double point;
char       ch,c=„5‟,name;


                            14
#include <stdio.h>
#define PI 3.414     const.c
int main()
{
                     3.414
  printf("%.3f",PI);
  getch();
  return 0;
}
                               15
•

•
    short arr[3];        :      :
    arr[0] = 50;        0020   50
                                2    arr
    arr[2] = 89;        0021   30
                                0
                        0022   211
    arr      20         0023   5
    arr[0]        50    0024   89
                               8
    arr[1]        211   0025   23
                                0
    arr[2]        89    0026   33
                        0027   12
                         :      :
                                           16
• “       ”
  (array of char)
      char s[5] = "Hello";
       printf("%c %c %cn", s[0], s[1], s[2]);


                   0 1 2 3 4
          S        H e l l o
               :
       H e l


                                                 17
/
•                             (           /
                      )
                 “stdio.h”
•
       scanf                         (
        %format)
•                                 (Output
    Function)
       printf                            (
        %format)                              18
•

•                                         printf
int c = 65;                                :
                                           2
printf("c (as a number) = %dn", c);
                                           30
printf("c (as a character) = %cn", c);
                                           65   c
                                           5
     :                                     8
c (as a number) = 65                       23
c (as a character) = A                     :


                                                    19
%format    scanf
       printf
                             %for
                             mat
        int                   %d
        long                 %ld
        long long            %lld
        unsigned int          %u
        unsigned long        %lu
        unsigned long long   %llu
        float                 %f
        double               %lf
        char                  %c
        char array[]          %s

                                    20
scanf
char name[20];
int age;

printf("Enter your name and age: ");
scanf("%s %d", name, &age);

printf("Hello %s.   You are %d years old.n",
   name, age);



     :
Enter your name and age: Tony 38
Hello Tony. You are 38 years old.



                                                21
•
                 START


                Statement1


                Statement2
     START

                Statement3
    Statement


      END       Statementn


                  END




                             22
Relational Operators
•
             (Operand)
Operator
     <
    <=
     >
    >=
    ==
    !=

                            23
Expression
•
  (Operand)
  (Operator)
A = 10; B = 3; C = 20;
Expressio
    n
A+B           13
(A + B) – C   -7
(C*B)+(A*B)   90
A%B           1
C%B           2
                             24
Relational Operators
•                               Relational
    Operators
i = 1; j = 2; k = 3;
    Expression
            i<j          true            1
       (i + j) >= k      true            1
    (j + k) > (i + 5)   false            0
          k != 3        false            0
          j == 2         true            1



                                             25
Logical (Bitwise) Operators
•
    (Operand)
      Operator Operator)
           (Logical
        &&                 AND

         ||                OR




                                 26
AND Operators
•


    A     B     A && B
True    True    T && T   True    1
True    False   T && F   False   0
False   True    F && T   False   0
False   False   F && F   False   0


                                     27
AND Operators
•                                        AND Operators
i = 8; j = 4.5; k = „z‟; // ascii    z        122
         Expression
(i >= 6) && (k == „z‟)              T && T == T          1
(i >= 6) && (k == 122)              T && T == T          1
(j >= 0) && (j != 4.5)              T && F == F          0
(k > 0) && (j != 5)                 T && T == T          1
(i < 0) && (j > 0) && (k > 0)       F && T && T ==       0
                                    F

                                                             28
OR Operators
•


    A     B     A || B
True    True    T || T   True    1
True    False   T || F   True    1
False   True    F || T   True    1
False   False   F || F   False   0


                                     29
OR Operators
•                                           OR Operators
i = 8; j = 4.5; k = „z‟; // ascii       z         122
       Expression
(i >= 6) || (k == „z‟)              T || T == T            1
(i >= 6) || (k != 122)              T || F == T            1
(j < 0) || (j != 4.5)               F || F == F            0
(k > 0) || (j != 5)                 T || T == T            1



                                                               30
•
i = 7; f = 4.5;
       Expression
f>5                 False   0
!(f > 5)            True    1
i <= 3              False   0
!(i <=3)            True    1
i > (f + 1)         True    1
!(i > (f + 1))      False   0


                                31
(Precedence)

•

                           Operators
unary operators        - , ++ , -- , ! , sizeof()   R->L
multiply, divide and           *,/,%                L->R
remainder
add and subtract                +,-                 L->R
relational                 < , <= , > , >=          L->R
equality                       == , !=              L->R
                                                           32
(Precedence)

•


                           Operators

and                             &&             L->R
or                               ||            L->R
assignment operators   =, +=, -=, *=, /=, %=   R->L
                                                      33
i = 8; j = 4.5; k = „z‟; // ascii     z         122
         Expression

i + j <= 10                    False                    0
i >= 8 && k == „z‟             True && True == True     1
k != „a‟ || i + j <= 10        True || False == True    1
k != „a‟ || i < j && k < i     True || False && False   0
                               == True && False
                               == False
k != „a‟ || i < j && k < i     True || False && False   1
                               == True || False
                               == True                      34
•
       if
       if…else
       if
       switch-case
•
       while loop
       do…while loop
       for loop
•                       35
if
          C Syntax                  Flowchart
     if (condition)           START
     {
       statement1;
           :                            true
                            condition
       statementN;
     }                      false        Statement


•               condition                Statement


    int
•                    {}        END

    condition


•                                                    36
if
#include <stdio.h>      if1.c
int main()
{                       I>J
  int i=101,j=100;
  if(i>j)
    printf("I > J");
  getch();
  return 0;
}                               37
if…else
          Flowchart                       C Syntax

              START                   if (condition)
                                      {
   true                 false           statementt1;
          condition
                                        statementt2;
Statementt1           Statementf1
                                      }
                                      else
Statementt2           Statementf2     {
                                        statementf1;
                                        statementf2;
               END                    }



                                                       38
if…else
#include <stdio.h>        ifelse1.c
int main()
{                          I <= J
  int i=101,j=102;
  if(i>j)
    printf("I > J");
  else
    printf("I <= J");
 getch();
 return 0;
}
                                      39
if
                                    if (x==1)
             true                     Action1;
      x==1          Action1;
   false
                                    else if (x==2)
      x==2
             true
                    Action2;          Action2;
   false                            else if (x==3)
             true
      x==3          Action3;          Action3;
   false
             true
                                    else if (x==4)
      x==4          Action4;
   false
                                      Action4;
Default_Action;                     else
                                      Default_Action;




                                                        40
if
#include <stdio.h>             ifelse2.c
int main()
{                                 >6
  int i=7;
  if(i>7) printf("> 7");
  else if(i>6) printf("> 6");
       else if(i>5) printf("i> 5");
          else printf("1 , 2 , 3");
 getch();
 return 0;
}
                                           41
switch-case
                                switch (x)
      x==1
             true
                    Action1;
                                {
                                 case 1: Action1;
   false
             true                        break;
      x==2          Action2;
                                 case 2: Action2;
   false
             true
                                         break;
      x==3          Action3;
                                 case 3: Action3;
   false
             true
                                         break;
      x==4          Action4;     case 4: Action4;
   false                                 break;
Default_Action;
                                 default: Default_Action;
                                           break;
                                }




                                                            42
switch-case
#include <stdio.h>
int main()                          switch1.c
{
  int i=2;
  switch(i)
  {
                                        2
    case 2 : printf("2");
         break;
    case 1 : printf("1");
         break;
    default : printf("NO MATCH");
           break;
  }
 getch();
 return 0;
}                                               43
i++    =    i
= i--1 =
  i+       i = i-
1
  i+=5 =   i=
i+i-=5 =
  5        i = i-
5                   44
while
     while (condition)            START
     {
        stmt1;
        stmt2;
        :                                    false
                                 condition
        stmtN;
     }                           true
                                 Statement
•                 stmt1
    stmtN                        Statement
                 condition

                                     END


                                                     45
Counting
              Loop)
•


•
    int i, sum = 0;
    i = 1;
    while (i <= 10)
    {
      sum = sum + i;
      i = i + 1;
    }
    printf("Sum = %dn", sum);


                                 46
while
#include <stdio.h>
int main()
                            while1.c
{                           Hello 1
                            Hello 2
  int i=1;                  Hello 3
  while(i<=10)              Hello 4
  {                         Hello 5
                            Hello 6
    printf("Hello %dn",i); Hello 7
    i++;                    Hello 8
 }                          Hello 9
                            Hello 10
 getch();
 return 0;
}                                      47
while
      (INFINITY LOOP)
#include <stdio.h>
int main()                    while2.c
{                             Hello 1
  int i=1;                    Hello 2
  while(1)                    Hello 3
  {                           Hello 4
    printf("Hello %dn",i);   Hello 5
    if(i==10)                 Hello 6
                              Hello 7
      break;                  Hello 8
  i++;                        Hello 9
 }                            Hello 10
 getch();
 return 0;
}                                        48
do…while
    do                                  START
    {
       stmt1;
       stmt2;
       :                               Statement1
       stmtN;
    } while (condition);
                                       StatementN

•             stmt1...stmtN
                                true
                                       condition

           condition                        false



•
                                          END
           stmt1...stmtN

                                                    49
do…while
#include <stdio.h>
                              dowhile1.c
int main()
{                              Hello 1
  int i=1;                     Hello 2
  do                           Hello 3
                               Hello 4
  {                            Hello 5
    printf("Hello %dn",i);    Hello 6
    i++;                       Hello 7
  }                            Hello 8
  while(i<=10);                Hello 9
 getch();                      Hello 10
 return 0;
}
                                           50
for
•
         for (init_stmt; condition; update_stmt)
         {
            statement1;
            statement2;
            :
            statementN;
         }



•
    1.             init_stmt

    2.      condition
     statement1...statementN
                                                   51
for
                                            START


                                           init_stmt

for (init_stmt; condition; update_stmt)
{
   statement1;
                                                        false
   statement2;                             condition
   :
   statementN;
}
                                           true
                                          Statement1


                                          StatementN


                                          update_stmt



                                             END
                                                                52
for
#include <stdio.h>
int main()                    for1.c
{                           Hello 1
                            Hello 2
  int i;                    Hello 3
  for(i=1;i<=10;i++)        Hello 4
  {                         Hello 5
                            Hello 6
    printf("Hello %d",i);   Hello 7
    printf("n");           Hello 8
  }                         Hello 9
                            Hello 10
 getch();
 return 0;
}                                      53
(Subroutine)
•                (Function)
•


•

    

    

    



                             54
•                      (Standard
    Functions)
    



        printf(), scanf(), ...
•                           (User Defined
    Functions)
    

                main()
                                            55
scanf, printf,
stdio.h
           gets, puts
math.h     sin, cos, exp, pow
           isalpha, isdigit,
ctype.h
           islower, isupper

string.h   strlen, strcpy,
           strcmp
stdlib.h   rand, atoi, atof



                                56
•                         void say_hi(char *name)
                          {
                           printf("Hi, %sn", name);
        void              }

    
        return
                          int max(int a, int b)
                          {
•                           if (a > b)
                              return a;
                            else
                             return b;
                          }

                return
                                                        57
#include <stdio.h>
int incr(int i)
{
  int j;
                           function1.c
  j = i + 1;
  return j;
}

int main()
{
  int k, m = 4;
  k = incr(m);
  printf ("k = %d, m = %dn", k, m);
  getch();
  return 0;
}

                                         58
(Function)

  #include <stdio.h>
  void print1()
  {
    printf(“Hello”);
                       function2.c
    printf(“n”);
  }

  int main()
  {
    print1();
    print1();
    getch();
    return 0;
  }

                                     59
(Function)
#include <stdio.h>
float cal_tax(float i)
{
                         function3.c
  float ctax;
  ctax = i*0.07;
  return ctax;
}

int main()
{
  float money=7290,ff;
  ff = cal_tax(money);
  printf(“%f”,ff);
  getch();
  return 0;
}
                                       60
•

•




    61
•
    Enter N: 3   Enter N: 5
    *            *
    **           **
    ***          ***
                 ****
                 *****




                              62
#include <stdio.h>

int main ()
{                      i     scanf
  int i;

    scanf("%d", i);
    if (i = 0)
      puts("false");   (=)
    else
      puts("true");
                                (==)

    return 0;
}




                                       63

Contenu connexe

Tendances

Tendances (20)

3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Manual de estándares mínimos
Manual de estándares mínimosManual de estándares mínimos
Manual de estándares mínimos
 
A new distance education certificate program .ppt
A new distance education certificate program .pptA new distance education certificate program .ppt
A new distance education certificate program .ppt
 
Building Relationships Through Social Media
Building Relationships Through Social MediaBuilding Relationships Through Social Media
Building Relationships Through Social Media
 
ภาษา C
ภาษา Cภาษา C
ภาษา C
 
Europea
EuropeaEuropea
Europea
 
C lab programs
C lab programsC lab programs
C lab programs
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
C programms
C programmsC programms
C programms
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Report
ReportReport
Report
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to Tinkerpop
 
input
inputinput
input
 
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDBScala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 

Similaire à โปรแกรมภาษาซีเบื้องต้น

Similaire à โปรแกรมภาษาซีเบื้องต้น (20)

pointers 1
pointers 1pointers 1
pointers 1
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Lab loop
Lab loopLab loop
Lab loop
 
ภาษาซีพื้นฐาน
ภาษาซีพื้นฐานภาษาซีพื้นฐาน
ภาษาซีพื้นฐาน
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
C language
C languageC language
C language
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
C tech questions
C tech questionsC tech questions
C tech questions
 
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdfLDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
LDCQ paper Dec21 with answer key_62cb2996afc60f6aedeb248c1d9283e5.pdf
 
深入淺出C語言
深入淺出C語言深入淺出C語言
深入淺出C語言
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Vcs14
Vcs14Vcs14
Vcs14
 
Vcs16
Vcs16Vcs16
Vcs16
 
Unit i intro-operators
Unit   i intro-operatorsUnit   i intro-operators
Unit i intro-operators
 
C multiple choice questions and answers pdf
C multiple choice questions and answers pdfC multiple choice questions and answers pdf
C multiple choice questions and answers pdf
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Vcs15
Vcs15Vcs15
Vcs15
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 

Plus de เทวัญ ภูพานทอง

การสืบค้นข้อมูลประเภทรูปภาพ
การสืบค้นข้อมูลประเภทรูปภาพการสืบค้นข้อมูลประเภทรูปภาพ
การสืบค้นข้อมูลประเภทรูปภาพเทวัญ ภูพานทอง
 
การสืบค้นข้อมูลประเภทข้อความ
การสืบค้นข้อมูลประเภทข้อความการสืบค้นข้อมูลประเภทข้อความ
การสืบค้นข้อมูลประเภทข้อความเทวัญ ภูพานทอง
 
เอกสารประกอบการพิจารณาครูดีในดวงใจ ปี 2559
เอกสารประกอบการพิจารณาครูดีในดวงใจ  ปี 2559เอกสารประกอบการพิจารณาครูดีในดวงใจ  ปี 2559
เอกสารประกอบการพิจารณาครูดีในดวงใจ ปี 2559เทวัญ ภูพานทอง
 
เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558
เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558
เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558เทวัญ ภูพานทอง
 
ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557
ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557
ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557เทวัญ ภูพานทอง
 
ใบความรู้ เรื่อง รูปแบบรายงานโครงงาน
ใบความรู้ เรื่อง รูปแบบรายงานโครงงานใบความรู้ เรื่อง รูปแบบรายงานโครงงาน
ใบความรู้ เรื่อง รูปแบบรายงานโครงงานเทวัญ ภูพานทอง
 
รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557
รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557
รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557เทวัญ ภูพานทอง
 
แบบเสนอขอรับรางวัล หนึ่งแสนครูดี
แบบเสนอขอรับรางวัล หนึ่งแสนครูดีแบบเสนอขอรับรางวัล หนึ่งแสนครูดี
แบบเสนอขอรับรางวัล หนึ่งแสนครูดีเทวัญ ภูพานทอง
 
รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556
รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556
รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556เทวัญ ภูพานทอง
 

Plus de เทวัญ ภูพานทอง (20)

คู่มือการใช้งาน Kahoot
คู่มือการใช้งาน Kahootคู่มือการใช้งาน Kahoot
คู่มือการใช้งาน Kahoot
 
คู่มือการใช้งาน Kahoot
คู่มือการใช้งาน Kahootคู่มือการใช้งาน Kahoot
คู่มือการใช้งาน Kahoot
 
คู่มือการใช้งาน Plicker
คู่มือการใช้งาน Plickerคู่มือการใช้งาน Plicker
คู่มือการใช้งาน Plicker
 
การสืบค้นข้อมูลชั้นสูง
การสืบค้นข้อมูลชั้นสูงการสืบค้นข้อมูลชั้นสูง
การสืบค้นข้อมูลชั้นสูง
 
การสืบค้นข้อมูลประเภทรูปภาพ
การสืบค้นข้อมูลประเภทรูปภาพการสืบค้นข้อมูลประเภทรูปภาพ
การสืบค้นข้อมูลประเภทรูปภาพ
 
การสืบค้นข้อมูลประเภทข้อความ
การสืบค้นข้อมูลประเภทข้อความการสืบค้นข้อมูลประเภทข้อความ
การสืบค้นข้อมูลประเภทข้อความ
 
กลยุทธ์การสืบค้นข้อมูล
กลยุทธ์การสืบค้นข้อมูลกลยุทธ์การสืบค้นข้อมูล
กลยุทธ์การสืบค้นข้อมูล
 
เครื่องมือค้นหา (Search engine)
เครื่องมือค้นหา (Search engine)เครื่องมือค้นหา (Search engine)
เครื่องมือค้นหา (Search engine)
 
ประเภทของ Search engine
ประเภทของ Search engineประเภทของ Search engine
ประเภทของ Search engine
 
เครื่องมือในการค้นหา
เครื่องมือในการค้นหาเครื่องมือในการค้นหา
เครื่องมือในการค้นหา
 
ประโยชน์ของการสืบค้น
ประโยชน์ของการสืบค้นประโยชน์ของการสืบค้น
ประโยชน์ของการสืบค้น
 
การค้นหาเว็บด้วย Internet Expolorer
การค้นหาเว็บด้วย Internet Expolorerการค้นหาเว็บด้วย Internet Expolorer
การค้นหาเว็บด้วย Internet Expolorer
 
เอกสารประกอบการพิจารณาครูดีในดวงใจ ปี 2559
เอกสารประกอบการพิจารณาครูดีในดวงใจ  ปี 2559เอกสารประกอบการพิจารณาครูดีในดวงใจ  ปี 2559
เอกสารประกอบการพิจารณาครูดีในดวงใจ ปี 2559
 
เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558
เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558
เอกสารประกอบการพิจารณา Obec Awards ปีการศึกษา 2558
 
ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557
ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557
ประกาศผล การประกวดสื่อของ สพฐ.ปีการศึกษา2557
 
ใบความรู้ เรื่อง รูปแบบรายงานโครงงาน
ใบความรู้ เรื่อง รูปแบบรายงานโครงงานใบความรู้ เรื่อง รูปแบบรายงานโครงงาน
ใบความรู้ เรื่อง รูปแบบรายงานโครงงาน
 
รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557
รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557
รายงานเยี่ยมบ้านนักเรียน ปีการศึกษา 2557
 
เอกสารเสนอ Best practice ครูเต้
เอกสารเสนอ Best practice ครูเต้เอกสารเสนอ Best practice ครูเต้
เอกสารเสนอ Best practice ครูเต้
 
แบบเสนอขอรับรางวัล หนึ่งแสนครูดี
แบบเสนอขอรับรางวัล หนึ่งแสนครูดีแบบเสนอขอรับรางวัล หนึ่งแสนครูดี
แบบเสนอขอรับรางวัล หนึ่งแสนครูดี
 
รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556
รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556
รายงานผลการปฏิบัติงานและการประเมินตนเอง ปี 2556
 

Dernier

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Dernier (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

โปรแกรมภาษาซีเบื้องต้น

  • 1.
  • 3. Dev-C++ • File > New > Source File • • .c  first.c 3
  • 4. Dev-C++ •   F9 • :  getch() 4
  • 5. main stdio.h #include <stdio.h> int int main() { int a, b, sum; printf() printf("Enter A: "); int scanf("%d", &a); a, b sum printf("Enter B: "); scanf("%d", &b); scanf() sum = a+b; printf("Sum = %dn", sum); getch(); return 0; } 0 ; 5
  • 6. (Comment) • • /* … ( )… */ // … ( )… /* arithmetic expression */ // create 6
  • 7. a (Beep) n (newline) backslash ’ 7
  • 8. (address) (data) 0000 32 1 =1 8 0001 67 0002 255 0003 0 0004 121 : : 8
  • 9. ( ) char 1 -128 +127 short 2 -32,768 +32,767 int 2 -32,768 - +32,767 4 2,147,483,648 +2,147,483,647 long 4 -2,147,483,648 +2,147,483,647 float 4 3.4 * 10-38 3.4 * 1038 double 8 1.7 * 10-308 1.7 * 10-308 9
  • 10. (Variable) •  ( ) : : short a, b, sum; 1000 10 2 a a = 10; 1001 30 0 b = 5; 1002 211 5 b sum = a+b; 1003 0 5 1004 15 8 sum 1005 23 0 : : b 5 ) &b 1002 10
  • 11. (Variable)  underscore ( _ )  underscore ( _ )  1-32  $  Case sensitive  Reserve words 11
  • 12. C auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof while do 12
  • 13. type variable-list [=value] ; • variable-list (,)  type  value 13
  • 14. int a=1; int lower; float man,ratio; double point; char ch,c=„5‟,name; 14
  • 15. #include <stdio.h> #define PI 3.414 const.c int main() { 3.414 printf("%.3f",PI); getch(); return 0; } 15
  • 16. • • short arr[3]; : : arr[0] = 50; 0020 50 2 arr arr[2] = 89; 0021 30 0 0022 211 arr 20 0023 5 arr[0] 50 0024 89 8 arr[1] 211 0025 23 0 arr[2] 89 0026 33 0027 12 : : 16
  • 17. • “ ” (array of char) char s[5] = "Hello"; printf("%c %c %cn", s[0], s[1], s[2]); 0 1 2 3 4 S H e l l o : H e l 17
  • 18. / • ( / ) “stdio.h” •  scanf ( %format) • (Output Function)  printf ( %format) 18
  • 19. • • printf int c = 65; : 2 printf("c (as a number) = %dn", c); 30 printf("c (as a character) = %cn", c); 65 c 5 : 8 c (as a number) = 65 23 c (as a character) = A : 19
  • 20. %format scanf printf %for mat int %d long %ld long long %lld unsigned int %u unsigned long %lu unsigned long long %llu float %f double %lf char %c char array[] %s 20
  • 21. scanf char name[20]; int age; printf("Enter your name and age: "); scanf("%s %d", name, &age); printf("Hello %s. You are %d years old.n", name, age); : Enter your name and age: Tony 38 Hello Tony. You are 38 years old. 21
  • 22. START Statement1 Statement2 START Statement3 Statement END Statementn END 22
  • 23. Relational Operators • (Operand) Operator < <= > >= == != 23
  • 24. Expression • (Operand) (Operator) A = 10; B = 3; C = 20; Expressio n A+B 13 (A + B) – C -7 (C*B)+(A*B) 90 A%B 1 C%B 2 24
  • 25. Relational Operators • Relational Operators i = 1; j = 2; k = 3; Expression i<j true 1 (i + j) >= k true 1 (j + k) > (i + 5) false 0 k != 3 false 0 j == 2 true 1 25
  • 26. Logical (Bitwise) Operators • (Operand) Operator Operator) (Logical && AND || OR 26
  • 27. AND Operators • A B A && B True True T && T True 1 True False T && F False 0 False True F && T False 0 False False F && F False 0 27
  • 28. AND Operators • AND Operators i = 8; j = 4.5; k = „z‟; // ascii z 122 Expression (i >= 6) && (k == „z‟) T && T == T 1 (i >= 6) && (k == 122) T && T == T 1 (j >= 0) && (j != 4.5) T && F == F 0 (k > 0) && (j != 5) T && T == T 1 (i < 0) && (j > 0) && (k > 0) F && T && T == 0 F 28
  • 29. OR Operators • A B A || B True True T || T True 1 True False T || F True 1 False True F || T True 1 False False F || F False 0 29
  • 30. OR Operators • OR Operators i = 8; j = 4.5; k = „z‟; // ascii z 122 Expression (i >= 6) || (k == „z‟) T || T == T 1 (i >= 6) || (k != 122) T || F == T 1 (j < 0) || (j != 4.5) F || F == F 0 (k > 0) || (j != 5) T || T == T 1 30
  • 31. • i = 7; f = 4.5; Expression f>5 False 0 !(f > 5) True 1 i <= 3 False 0 !(i <=3) True 1 i > (f + 1) True 1 !(i > (f + 1)) False 0 31
  • 32. (Precedence) • Operators unary operators - , ++ , -- , ! , sizeof() R->L multiply, divide and *,/,% L->R remainder add and subtract +,- L->R relational < , <= , > , >= L->R equality == , != L->R 32
  • 33. (Precedence) • Operators and && L->R or || L->R assignment operators =, +=, -=, *=, /=, %= R->L 33
  • 34. i = 8; j = 4.5; k = „z‟; // ascii z 122 Expression i + j <= 10 False 0 i >= 8 && k == „z‟ True && True == True 1 k != „a‟ || i + j <= 10 True || False == True 1 k != „a‟ || i < j && k < i True || False && False 0 == True && False == False k != „a‟ || i < j && k < i True || False && False 1 == True || False == True 34
  • 35.  if  if…else  if  switch-case •  while loop  do…while loop  for loop • 35
  • 36. if C Syntax Flowchart if (condition) START { statement1; : true condition statementN; } false Statement • condition Statement int • {} END condition • 36
  • 37. if #include <stdio.h> if1.c int main() { I>J int i=101,j=100; if(i>j) printf("I > J"); getch(); return 0; } 37
  • 38. if…else Flowchart C Syntax START if (condition) { true false statementt1; condition statementt2; Statementt1 Statementf1 } else Statementt2 Statementf2 { statementf1; statementf2; END } 38
  • 39. if…else #include <stdio.h> ifelse1.c int main() { I <= J int i=101,j=102; if(i>j) printf("I > J"); else printf("I <= J"); getch(); return 0; } 39
  • 40. if if (x==1) true Action1; x==1 Action1; false else if (x==2) x==2 true Action2; Action2; false else if (x==3) true x==3 Action3; Action3; false true else if (x==4) x==4 Action4; false Action4; Default_Action; else Default_Action; 40
  • 41. if #include <stdio.h> ifelse2.c int main() { >6 int i=7; if(i>7) printf("> 7"); else if(i>6) printf("> 6"); else if(i>5) printf("i> 5"); else printf("1 , 2 , 3"); getch(); return 0; } 41
  • 42. switch-case switch (x) x==1 true Action1; { case 1: Action1; false true break; x==2 Action2; case 2: Action2; false true break; x==3 Action3; case 3: Action3; false true break; x==4 Action4; case 4: Action4; false break; Default_Action; default: Default_Action; break; } 42
  • 43. switch-case #include <stdio.h> int main() switch1.c { int i=2; switch(i) { 2 case 2 : printf("2"); break; case 1 : printf("1"); break; default : printf("NO MATCH"); break; } getch(); return 0; } 43
  • 44. i++ = i = i--1 = i+ i = i- 1 i+=5 = i= i+i-=5 = 5 i = i- 5 44
  • 45. while while (condition) START { stmt1; stmt2; : false condition stmtN; } true Statement • stmt1 stmtN Statement condition END 45
  • 46. Counting Loop) • • int i, sum = 0; i = 1; while (i <= 10) { sum = sum + i; i = i + 1; } printf("Sum = %dn", sum); 46
  • 47. while #include <stdio.h> int main() while1.c { Hello 1 Hello 2 int i=1; Hello 3 while(i<=10) Hello 4 { Hello 5 Hello 6 printf("Hello %dn",i); Hello 7 i++; Hello 8 } Hello 9 Hello 10 getch(); return 0; } 47
  • 48. while (INFINITY LOOP) #include <stdio.h> int main() while2.c { Hello 1 int i=1; Hello 2 while(1) Hello 3 { Hello 4 printf("Hello %dn",i); Hello 5 if(i==10) Hello 6 Hello 7 break; Hello 8 i++; Hello 9 } Hello 10 getch(); return 0; } 48
  • 49. do…while do START { stmt1; stmt2; : Statement1 stmtN; } while (condition); StatementN • stmt1...stmtN true condition condition false • END stmt1...stmtN 49
  • 50. do…while #include <stdio.h> dowhile1.c int main() { Hello 1 int i=1; Hello 2 do Hello 3 Hello 4 { Hello 5 printf("Hello %dn",i); Hello 6 i++; Hello 7 } Hello 8 while(i<=10); Hello 9 getch(); Hello 10 return 0; } 50
  • 51. for • for (init_stmt; condition; update_stmt) { statement1; statement2; : statementN; } • 1. init_stmt 2. condition statement1...statementN 51
  • 52. for START init_stmt for (init_stmt; condition; update_stmt) { statement1; false statement2; condition : statementN; } true Statement1 StatementN update_stmt END 52
  • 53. for #include <stdio.h> int main() for1.c { Hello 1 Hello 2 int i; Hello 3 for(i=1;i<=10;i++) Hello 4 { Hello 5 Hello 6 printf("Hello %d",i); Hello 7 printf("n"); Hello 8 } Hello 9 Hello 10 getch(); return 0; } 53
  • 54. (Subroutine) • (Function) • •     54
  • 55. (Standard Functions)   printf(), scanf(), ... • (User Defined Functions)   main() 55
  • 56. scanf, printf, stdio.h gets, puts math.h sin, cos, exp, pow isalpha, isdigit, ctype.h islower, isupper string.h strlen, strcpy, strcmp stdlib.h rand, atoi, atof 56
  • 57. void say_hi(char *name) {  printf("Hi, %sn", name); void }  return int max(int a, int b) { • if (a > b) return a; else  return b; }  return 57
  • 58. #include <stdio.h> int incr(int i) { int j; function1.c j = i + 1; return j; } int main() { int k, m = 4; k = incr(m); printf ("k = %d, m = %dn", k, m); getch(); return 0; } 58
  • 59. (Function) #include <stdio.h> void print1() { printf(“Hello”); function2.c printf(“n”); } int main() { print1(); print1(); getch(); return 0; } 59
  • 60. (Function) #include <stdio.h> float cal_tax(float i) { function3.c float ctax; ctax = i*0.07; return ctax; } int main() { float money=7290,ff; ff = cal_tax(money); printf(“%f”,ff); getch(); return 0; } 60
  • 61. • • 61
  • 62. Enter N: 3 Enter N: 5 * * ** ** *** *** **** ***** 62
  • 63. #include <stdio.h> int main () { i scanf int i; scanf("%d", i); if (i = 0) puts("false"); (=) else puts("true"); (==) return 0; } 63