SlideShare a Scribd company logo
1 of 64
1.

 Preprocessing Directive


 #include <stdio.h>

     stdio.h

 preprocessing directives



               2
- #include <
  >


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




            comment)

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

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


                                     printf()

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




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

%s

%   d
%   u
%   f
%   e   e

%x
%o
              1.1
    printf()

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

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

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

22.75
2.28e+01
         printf ( )

                       printf( )
    print format





    %d

    %u

    %f

    %c       1

    %s
         1





    n
    t   tab         8
    a
             Backslash


    printf( )
5 + 5 = 10

             printf( )   string format
Hello word

             3            2
              data list



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

•                        d           2
•                        d           a

•                        s           b



      f)
    printf( )

                f

                     6
               printf( )         n)

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

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


      (,)
                             &
                  control

                        “”

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

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

    var = expression ;




                 var = expression ;


     var
    Expression
                  : expression

    var = expression ;




                 var = expression ;


     var
    Expression


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


                           putchar()

    intputchar (<character>);
            putchar()




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

Aa
2   getchar ( )
       getchar ( )
                         1
        enter

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

      enter

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

       enter

           getche ( );
 3.                          –

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

                string
          char [ n ]


    put


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

    enter

               gets
gets          ; ;




                   string_var = get   ;


string_var = get              ;



    -
                          enter

              gets word ;
    -

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

More Related Content

What's hot

โปรแกรมย่อยและฟังชันก์มาตรฐาน
โปรแกรมย่อยและฟังชันก์มาตรฐานโปรแกรมย่อยและฟังชันก์มาตรฐาน
โปรแกรมย่อยและฟังชันก์มาตรฐาน
knang
 
C basics
C basicsC basics
C basics
MSc CST
 

What's hot (20)

Single linked list
Single linked listSingle linked list
Single linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
โปรแกรมย่อยและฟังชันก์มาตรฐาน
โปรแกรมย่อยและฟังชันก์มาตรฐานโปรแกรมย่อยและฟังชันก์มาตรฐาน
โปรแกรมย่อยและฟังชันก์มาตรฐาน
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C basics
C basicsC basics
C basics
 
C programms
C programmsC programms
C programms
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
Circular queue
Circular queueCircular queue
Circular queue
 
week-16x
week-16xweek-16x
week-16x
 
Avl tree
Avl treeAvl tree
Avl tree
 

Viewers also liked

ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
mycomc55
 

Viewers also liked (11)

ภาษาซีเบื้องต้น
ภาษาซีเบื้องต้นภาษาซีเบื้องต้น
ภาษาซีเบื้องต้น
 
การเขียนโปรแกรมภาษา
การเขียนโปรแกรมภาษาการเขียนโปรแกรมภาษา
การเขียนโปรแกรมภาษา
 
การเขียนคำสั่งควบคุมแบบมีทางเลือก
การเขียนคำสั่งควบคุมแบบมีทางเลือกการเขียนคำสั่งควบคุมแบบมีทางเลือก
การเขียนคำสั่งควบคุมแบบมีทางเลือก
 
การเขียนโปรแกรม
การเขียนโปรแกรมการเขียนโปรแกรม
การเขียนโปรแกรม
 
ใบความรู้ที่5 การสร้างภาพเคลื่อนไหว (Tweened Animation)
ใบความรู้ที่5 การสร้างภาพเคลื่อนไหว (Tweened Animation)ใบความรู้ที่5 การสร้างภาพเคลื่อนไหว (Tweened Animation)
ใบความรู้ที่5 การสร้างภาพเคลื่อนไหว (Tweened Animation)
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
สื่อการสอนเกี่ยวกับทัศนธาตุในงานศิลปะชั้นมัธยมศึกษาปีที่ 2
สื่อการสอนเกี่ยวกับทัศนธาตุในงานศิลปะชั้นมัธยมศึกษาปีที่  2สื่อการสอนเกี่ยวกับทัศนธาตุในงานศิลปะชั้นมัธยมศึกษาปีที่  2
สื่อการสอนเกี่ยวกับทัศนธาตุในงานศิลปะชั้นมัธยมศึกษาปีที่ 2
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
การเขียนคำสั่งขั้นพื้นฐาน(ภาษาC)
การเขียนคำสั่งขั้นพื้นฐาน(ภาษาC)การเขียนคำสั่งขั้นพื้นฐาน(ภาษาC)
การเขียนคำสั่งขั้นพื้นฐาน(ภาษาC)
 
บทที่1 พื้นฐานโปรแกรมภาษาซี
บทที่1 พื้นฐานโปรแกรมภาษาซีบทที่1 พื้นฐานโปรแกรมภาษาซี
บทที่1 พื้นฐานโปรแกรมภาษาซี
 
เรื่องภาษาซี
เรื่องภาษาซีเรื่องภาษาซี
เรื่องภาษาซี
 

Similar to ภาษาซี

โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
Little Tukta Lita
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
Little Tukta Lita
 
ภาษาซีพื้นฐาน
ภาษาซีพื้นฐานภาษาซีพื้นฐาน
ภาษาซีพื้นฐาน
Krunee Thitthamon
 

Similar to ภาษาซี (20)

โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Lab loop
Lab loopLab loop
Lab loop
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
C Programming lab
C Programming labC Programming lab
C Programming lab
 
programs
programsprograms
programs
 
ภาษาซีพื้นฐาน
ภาษาซีพื้นฐานภาษาซีพื้นฐาน
ภาษาซีพื้นฐาน
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Arrays
ArraysArrays
Arrays
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 

More from kramsri

ข อสอบคอม 5 ข อส่ง
ข อสอบคอม 5 ข อส่งข อสอบคอม 5 ข อส่ง
ข อสอบคอม 5 ข อส่ง
kramsri
 
ข อสอบคอม #6
ข อสอบคอม #6ข อสอบคอม #6
ข อสอบคอม #6
kramsri
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1
kramsri
 
คำสั่ง Switch.2
คำสั่ง Switch.2คำสั่ง Switch.2
คำสั่ง Switch.2
kramsri
 
คำสั่ง Switch
คำสั่ง Switchคำสั่ง Switch
คำสั่ง Switch
kramsri
 
คำสั่ง Switch
คำสั่ง Switchคำสั่ง Switch
คำสั่ง Switch
kramsri
 
คำสั่ง Switch
คำสั่ง Switchคำสั่ง Switch
คำสั่ง Switch
kramsri
 
คำสั่ง For
คำสั่ง Forคำสั่ง For
คำสั่ง For
kramsri
 
คำสั่ง Do while
คำสั่ง Do whileคำสั่ง Do while
คำสั่ง Do while
kramsri
 
คำสั่ง Do while
คำสั่ง Do whileคำสั่ง Do while
คำสั่ง Do while
kramsri
 
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)
kramsri
 
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_
kramsri
 
ความคิดเห็นเพื่อน(แบบประเมิน)
ความคิดเห็นเพื่อน(แบบประเมิน)ความคิดเห็นเพื่อน(แบบประเมิน)
ความคิดเห็นเพื่อน(แบบประเมิน)
kramsri
 
ประกวดภาพถ่าย
ประกวดภาพถ่ายประกวดภาพถ่าย
ประกวดภาพถ่าย
kramsri
 

More from kramsri (14)

ข อสอบคอม 5 ข อส่ง
ข อสอบคอม 5 ข อส่งข อสอบคอม 5 ข อส่ง
ข อสอบคอม 5 ข อส่ง
 
ข อสอบคอม #6
ข อสอบคอม #6ข อสอบคอม #6
ข อสอบคอม #6
 
งานนำเสนอ1
งานนำเสนอ1งานนำเสนอ1
งานนำเสนอ1
 
คำสั่ง Switch.2
คำสั่ง Switch.2คำสั่ง Switch.2
คำสั่ง Switch.2
 
คำสั่ง Switch
คำสั่ง Switchคำสั่ง Switch
คำสั่ง Switch
 
คำสั่ง Switch
คำสั่ง Switchคำสั่ง Switch
คำสั่ง Switch
 
คำสั่ง Switch
คำสั่ง Switchคำสั่ง Switch
คำสั่ง Switch
 
คำสั่ง For
คำสั่ง Forคำสั่ง For
คำสั่ง For
 
คำสั่ง Do while
คำสั่ง Do whileคำสั่ง Do while
คำสั่ง Do while
 
คำสั่ง Do while
คำสั่ง Do whileคำสั่ง Do while
คำสั่ง Do while
 
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ (1)
 
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_
ประเม นรายงาน กล _มท__ 2 คำส__งควบค_มข__นพ__นฐานภาษาซ_
 
ความคิดเห็นเพื่อน(แบบประเมิน)
ความคิดเห็นเพื่อน(แบบประเมิน)ความคิดเห็นเพื่อน(แบบประเมิน)
ความคิดเห็นเพื่อน(แบบประเมิน)
 
ประกวดภาพถ่าย
ประกวดภาพถ่ายประกวดภาพถ่าย
ประกวดภาพถ่าย
 

ภาษาซี

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