SlideShare une entreprise Scribd logo
1  sur  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 ;


Contenu connexe

Tendances (20)

Single linked list
Single linked listSingle linked list
Single linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
โปรแกรมย่อยและฟังชันก์มาตรฐาน
โปรแกรมย่อยและฟังชันก์มาตรฐานโปรแกรมย่อยและฟังชันก์มาตรฐาน
โปรแกรมย่อยและฟังชันก์มาตรฐาน
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
week-16x
week-16xweek-16x
week-16x
 
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 Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C basics
C basicsC basics
C basics
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
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
 
C programms
C programmsC programms
C programms
 
Circular queue
Circular queueCircular queue
Circular queue
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 

En vedette

Impress nataciíon
Impress nataciíonImpress nataciíon
Impress nataciíonPatryAlba
 
Folleto 1 antecedentes sociologia
Folleto  1   antecedentes sociologiaFolleto  1   antecedentes sociologia
Folleto 1 antecedentes sociologiaJeanethe Toruño
 
Edu614 session 4 ws 12 photos pinterest
Edu614 session 4 ws 12 photos pinterestEdu614 session 4 ws 12 photos pinterest
Edu614 session 4 ws 12 photos pinterestKathy Favazza
 
Poblaciones dispersas y excluidas aisped
Poblaciones dispersas y excluidas aispedPoblaciones dispersas y excluidas aisped
Poblaciones dispersas y excluidas aispedAna Maria
 
Whitepaper De Nieuwe Competentie Integrale Flexibiliteit
Whitepaper De Nieuwe Competentie Integrale FlexibiliteitWhitepaper De Nieuwe Competentie Integrale Flexibiliteit
Whitepaper De Nieuwe Competentie Integrale Flexibiliteitrinuswit
 
Virus informáticos y solucion
Virus informáticos y solucionVirus informáticos y solucion
Virus informáticos y solucionjhonhernandez87
 
Virus InformáTicos
Virus InformáTicosVirus InformáTicos
Virus InformáTicosezzati
 
G6 m5-a-lesson 4-t
G6 m5-a-lesson 4-tG6 m5-a-lesson 4-t
G6 m5-a-lesson 4-tmlabuski
 
T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...
T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...
T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...Hernan Florez
 
Propostas para cultura - Déda13
Propostas para cultura - Déda13Propostas para cultura - Déda13
Propostas para cultura - Déda13Marcelo Déda 13
 
Chapter 9 learning more about sample data(1)
Chapter 9 learning more about sample data(1)Chapter 9 learning more about sample data(1)
Chapter 9 learning more about sample data(1)Celumusa Godfrey Nkosi
 
National educational technology standards for students and teachers web 2.0
National educational technology standards for students and teachers web 2.0National educational technology standards for students and teachers web 2.0
National educational technology standards for students and teachers web 2.0erincrandall
 
Cesa 4 presentation
Cesa 4 presentationCesa 4 presentation
Cesa 4 presentationbradfordgs
 
Year 1 session 25 slides 2014
Year 1 session 25 slides 2014Year 1 session 25 slides 2014
Year 1 session 25 slides 2014vikkis
 
Fixed Designs for Psychological Research
Fixed Designs for Psychological ResearchFixed Designs for Psychological Research
Fixed Designs for Psychological ResearchGrant Heller
 

En vedette (20)

Impress nataciíon
Impress nataciíonImpress nataciíon
Impress nataciíon
 
Folleto 1 antecedentes sociologia
Folleto  1   antecedentes sociologiaFolleto  1   antecedentes sociologia
Folleto 1 antecedentes sociologia
 
Edu614 session 4 ws 12 photos pinterest
Edu614 session 4 ws 12 photos pinterestEdu614 session 4 ws 12 photos pinterest
Edu614 session 4 ws 12 photos pinterest
 
Eletronica senai
Eletronica senaiEletronica senai
Eletronica senai
 
Poblaciones dispersas y excluidas aisped
Poblaciones dispersas y excluidas aispedPoblaciones dispersas y excluidas aisped
Poblaciones dispersas y excluidas aisped
 
Whitepaper De Nieuwe Competentie Integrale Flexibiliteit
Whitepaper De Nieuwe Competentie Integrale FlexibiliteitWhitepaper De Nieuwe Competentie Integrale Flexibiliteit
Whitepaper De Nieuwe Competentie Integrale Flexibiliteit
 
Marco legal
Marco legalMarco legal
Marco legal
 
Virus informáticos y solucion
Virus informáticos y solucionVirus informáticos y solucion
Virus informáticos y solucion
 
Virus InformáTicos
Virus InformáTicosVirus InformáTicos
Virus InformáTicos
 
Seguridad informatica
Seguridad informaticaSeguridad informatica
Seguridad informatica
 
G6 m5-a-lesson 4-t
G6 m5-a-lesson 4-tG6 m5-a-lesson 4-t
G6 m5-a-lesson 4-t
 
T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...
T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...
T%c3%a9cnico%20en%20 explotaciones%20agropecuarias%20ecol%c3%b3gicas%20sofia%...
 
Propostas para cultura - Déda13
Propostas para cultura - Déda13Propostas para cultura - Déda13
Propostas para cultura - Déda13
 
Unit 2
Unit 2Unit 2
Unit 2
 
Chapter 9 learning more about sample data(1)
Chapter 9 learning more about sample data(1)Chapter 9 learning more about sample data(1)
Chapter 9 learning more about sample data(1)
 
National educational technology standards for students and teachers web 2.0
National educational technology standards for students and teachers web 2.0National educational technology standards for students and teachers web 2.0
National educational technology standards for students and teachers web 2.0
 
Cesa 4 presentation
Cesa 4 presentationCesa 4 presentation
Cesa 4 presentation
 
Year 1 session 25 slides 2014
Year 1 session 25 slides 2014Year 1 session 25 slides 2014
Year 1 session 25 slides 2014
 
Fixed Designs for Psychological Research
Fixed Designs for Psychological ResearchFixed Designs for Psychological Research
Fixed Designs for Psychological Research
 
SISTEMAS POLÍTICOS Y FORMAS DE GOBIERNO
SISTEMAS POLÍTICOS Y FORMAS DE GOBIERNOSISTEMAS POLÍTICOS Y FORMAS DE GOBIERNO
SISTEMAS POLÍTICOS Y FORMAS DE GOBIERNO
 

Similaire à C Preprocessing Directives and Input/Output Functions Guide

โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1Little Tukta Lita
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkarsandeep kumbhkar
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointersvinay arora
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements loopingMomenMostafa
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1Little Tukta Lita
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
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.2020vrgokila
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
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 ...DR B.Surendiran .
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdfsowmya koneru
 
Program flowchart
Program flowchartProgram flowchart
Program flowchartSowri Rajan
 

Similaire à C Preprocessing Directives and Input/Output Functions Guide (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
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
 
Lab loop
Lab loopLab loop
Lab loop
 
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
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
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 ...
 
programs
programsprograms
programs
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
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
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Progr2
Progr2Progr2
Progr2
 

Plus de kramsri

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

Plus de 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 คำส__งควบค_มข__นพ__นฐานภาษาซ_
 
ความคิดเห็นเพื่อน(แบบประเมิน)
ความคิดเห็นเพื่อน(แบบประเมิน)ความคิดเห็นเพื่อน(แบบประเมิน)
ความคิดเห็นเพื่อน(แบบประเมิน)
 
ประกวดภาพถ่าย
ประกวดภาพถ่ายประกวดภาพถ่าย
ประกวดภาพถ่าย
 

C Preprocessing Directives and Input/Output Functions Guide

  • 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.