SlideShare una empresa de Scribd logo
1 de 74
C PROGRAMMING
   TUTORIAL



   By: gajendra singh rathore
OUTLINE
   Overview
   History
   Features
   Role of C Compiler
   Flowchart
   Sample C Program 1
   Character Set
   Data Types
   Variables
   C is Case Sensitive
   C Token
   Sample C Program 2
   Control Statements
   Common Programming Errors   2
   Assignment
OVERVIEW OF C
   C language is

     Structured


     High   level

     Machine   independent

     Follows   top down approach



                                    3
HISTORY
   ALGOL
     In 1960’s
     First language using a block structure

   BCPL
     In1967
     Basic Combined Programming Language

   B
     In1970
     Added feature of BCPL



                                               4
CONTD…


   C
     Evolved   from ALGOL, BCPL & B

     Developed   between 1969 and 1973 along with Unix

     Developed   at AT & T’s Bell Laboratories of USA

     Designed   and written by Dennis Ritchie

                                                          5
FEATURES
   C is PortableThis means a program written for
    one computer may run successfully on other
    computer also.

   C is fast
    This means that the executable program
    obtained after compiling and linking runs very
    fast.

   C is compact
    The statements in C Language are generally       6
    short but very powerful.
CONTD…

   Simple / Easy
    The C Language has both the simplicity of High Level
    Language and speed of Low Level Language. So it is
    also known as Middle Level Language

   C has only 32 Keywords

   C Compiler is easily available

   C has ability to extend itself. Users can add their own   7
    functions to the C Library
ROLE OF C COMPILER
    Compiler:   converts source to object code for a specific
     platform
    Linker: resolves external references and produces the
     executable module
 Typically C programs when executing, have four different files
    Source Code – file that is created by user and the
     executable statements are written. This file is saved with a
     file extension of ‘.c’.
    Header files – contains the declaration of functions and pre-
     processors statements. Header files have ‘.h’ as their
     extension.
    Object files – are the output from the compilers. ‘.o’ or
     ‘.obj’ are the typical extension to such files.              8
    Binary executables – are an output of the process of
     linking. Binary executables have ‘.exe’ as their extension.
FLOWCHART
   Flow charts are symbolic diagrams of operations
    and the sequence, data flow, control flow and
    processing logic in information processing.

   These charts are used to understand any working
    sequence of the program.

   Flow char is a graphical representation of
    algorithm.

   An algorithm defines as the step by step
    procedure or method that can be carried out for   9
    solving programming problems.
CONTD…
Advantages of flowchart:-

   It provides an easy way of communication
    because any other person besides the
    programmer can understand the way they are
    represented.

   It represents the data flow.

   It provides a clear overview of the entire program
    and problem and solution.                            10
CONTD…

   It checks the accuracy in logic flow.

   It documents the steps followed in an algorithm.

   It provides the facility for coding.

   It provides the way of modification of running
    program.

   They shows all major elements and their
    relationship.                                      11
FLOWCHART SYMBOLS




                    12
CONTD…
   Terminator
     This symbol represents the beginning and end
    point in a program. We use start and stop option
    in it.

   Input / Output Symbol
     This symbol is used to take any input or output
    in the algorithm.

   Process Symbol
     A rectangle indicates the processing, calculation
                                                         13
    and arithmetic operations
CONTD…
   Decision Symbol
     It is used when we want to take any decision in
    the program.

   Connector Symbol
      This symbol is used to connect the various
    portion of a flow chart. This is normally used
    when the flow chart is split between two pages

   Data Flow Symbol
     This symbol is used to display the flow of the    14
    program. It shows the path of logic flow in a
    program.
SAMPLE C PROGRAM

 main() --------------Function name
 {     ------------Start of Program
        ….
        …. -------- Program statements
        ….
  } --------------- End of Program



                                         15
CONTD…

/*   Filename    : hello.c
     Description : This program prints the greeting
                  “Hello, World!”
*/
     #include <stdio.h>               #include <stdio.h>
                                     int main(void)
     void main( )                    {
     {                                   printf ( “Hello, World!n” ) ;
        printf ( “Hello, World!n”);     return 0 ;
        getch();                     }
     }
                                                                 16
FLOWCHART FOR HELLO.C
                                 An oval denotes either
 int main ()                     the start or the end of
 {
                                 the program, or a halt
    printf("Hello, world!n");
 }                               operation within the
            Start                program (which we’ll
                                 learn about later).

                                 A parallelogram
    Output “Hello, world!”
                                 denotes either an input
                                 operation or an output
                                 operation.
             End
                                 An arrow denotes the
                                 flow of the program.

                                                17
CONTD…
 Comments
    Text surrounded by /* and */ is ignored by computer
    Used to describe program
 int main()

    Program’s execution starts from the main function
    Parenthesis used to indicate a function
    int means that main "returns" an integer value
    Braces ({ and }) indicate a block
       The bodies of all functions must be contained in braces


                                                              18
CONTD…
o   Preprocessor directives

         #include <stdio.h>
         #include <conio.h>
         #include <stdlib.h>
         #include <string.h>

   The #include directives “paste” the contents of the files
    like stdio.h and conio.h into your source code, at the
    very place where the directives appear.

                                                                19
CONTD…
   These files contain information about some library
    functions used in the program:
      stdio stands for “standard I/O”,
      conio stands for “console I/O”
      stdlib stands for “standard library”,
      string.h includes useful string manipulation functions.


   Want to see the files? Look in /TC/include



                                                                 20
CONTD…
#define MAX_COLS 20
#define MAX_INPUT 1000


   The #define directives perform “global replacements”:

     every instance of MAX_COLS is replaced with 20,
      and every instance of MAX_INPUT is replaced with
      1000



                                                            21
CONTD…
 commonly    used stdio.h functions:

  printf() – Output function
    Syntax:

    printf(“….”) ;

  scanf() – Input function
    Syntax:

    scanf(“format specifier”, &var,&var2…);      22
CONTD…

   commonly used conio.h functions:

    clrscr()
      Used to clear the screen

    getch()
      Used to get a character from ouput screen to
       come into the edit screen.
                                                      23
CHARACTER SET
These are the characters that C recognizes.
Letters (upper case and lower case)
AB C DE F G H I J KLM
NOPQRSTUVWXYZ
abcdefghijklm
nopqrstuvwxyz
Digits
0123456789
 Special Characters (punctuation etc)
space (also known as blank)
’" ( ) * + - / : =
!&$;<>%?,.
ˆ#@˜‘{}[]|                                   24
CONTD…
   256 characters are allowed in C.

    A –  Z : 65 to 90                   26
    a – z    : 97 to 122                26
    0 – 9    : 48 to 57                 10
     Special symbols[ #, &, `…]         32
     Control characters[n, t . ..]    34
     Graphic characters                128

       Total                            256   25
DATA TYPES
o C support several different types of data, which may be
represented differently within the computers memory.

o Types

    1] Primary       2] Derived            3] User Defined
        Integer         Arrays               typedef
        Float           Pointers             enum
        Double          Structure
        Character



                                                             26
CONTD…
   Primary Data Types

Data Types               Byte   Format Specifier
1] char                    1            %c
   signed char             1            %c
   unsigned char           1            %c

2] short                   2            %d
   short signed int        2            %d
   short unsigned int      2            %u

3] int                     2            %d
                                                   27
   signed int              2            %d
   unsigned int            2            %u
CONTD…
Data Types           Byte   Format Specifier
4] long                 4        %l
   long signed int     4        %ld
   long unsigned int   4         %lu

5] float               4         %f
   signed float        4         %f
   unsigned float      4         %uf

6] double              8          %lf
                                               28
7] Long Double        10         %Lf
TYPE CASTING
   It is used to convert on data at a time.

   We can have two types of type casting.
     Implicit
     Explicit


       Implicit : This converts narrow type to wider type so
        that user can avoid the information to the system.

   Explicit : Explicit type casting is done by the
    programmer manually. When the programmer
    wants a result of an expression to be in
    particular type, then we use explicit type casting.
    This type casting is done by casting operators ‘( )’        29

    and data type.
CONTD…
#include <stdio.h>
void main( )
{
  int base, height, area;
  base = 5;
   height =3;
   area = (base * height)/2;
   printf ( “Area = %d n”, area);
}
Output : Area = 7              ……………………. Incorrect
                                                     30
CONTD…
#include <stdio.h>
void main( )
{
  int base, height, area;
  base = 5;
   height = 3;
   area = ((float) (base * height)/2);
   printf ( “Area = %d n”, area);
}
Output : Area = 7.5           …………………….Correct

                                                  31
USER DEFINED DATA TYPE
[A] Type Definition

  Allows  user to define an identifier that would
   represent an existing data type

  Syntax:   typedef type identifier

  Eg:   typedef int units;
          units batch1, batch2;
                                                     32
CONTD…
[B] Enumerated data type

 Syntax:   enum identifier { value1, value2...
 valuen}

 Eg:
    enum day{ Monday, Tuesday, Wednesday,
 Thursday, Friday, Saturday, Sunday}



                                                  33
VARIABLES
 Variable names correspond to locations in the computer's
  memory
 Data name that may be used to store a data value

 It may take different values at different times during
  execution
 Eg:

    char x;
    char y = ‘e’;




                                                             34
CONTD…
   Rules
     Must begin with a letter(), some system permits
      underscore as first character.
     Length should be not more than 8 characters
     Uppercase and lowercase are significant, (i.e.) total
      and TOTAL are different
     Variable should not be a keyword
     White space is not allowed




                                                              35
C IS CASE SENSITIVE
C is case sensitive: it distinguishes between UPPER case
  (CAPITAL) and lower case (small) letters.
Keywords in C — for example, the keyword int — MUST be
  in lower case. For example:

#include <stdio.h>
  int main ()
  { /* main */
                 int height_in_cm;
                 height_in_cm = 160;
   printf("My height is %d cm.n",height_in_cm);
} /* main */
                                                       36
C TOKENS
    Keywords
    Identifiers

    Constants

    Strings

    Special Symbol

    Operators




                      37
CONTD…
   Keywords
     C uses 32 keyword
     have fixed meaning and cannot be changed


Keywords
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        volatile
do              if           static        while

                                                      38
CONTD…
   Constants
     Quantity that does not change is called a constant.


     Types
          Numeric constants
            Integer constants – 123, -33

            Real constants – 0.992, 3.5e2



          Character constants
            Single character constants – ‘5’, ‘a’

            String Constants – ‘Hello’, ‘1999’

                                                            39
CONTD…
Backslash Characters Constants

 n – Newline
 b – Backspace
 f – Form feed
 t – Tab or horizontal tab
 a – Audible alert
 r – Carriage return
 v – Vertical Tab
 ’ – Single Quote
 ” – Double Quote
 ? – Question Mark
  - Backslash
                                 40
 0 - Null
CONTD…
 Identifiers

  Names      of arrays, function and variable

 Operators

  Arithmetic
  Relational
  Logical
  Bitwise
                                                 41
CONTD….
ARITHMETIC OPERATORS

C operation    Arithmetic   Algebraic C expression
               operator     expression
Addition       +            f+7        f+7
Subtraction    -            p–c        p-c
Multiplication *            bm         b*m
Division       /            x/y        x/y
Modulus        %            r mod s r % s

                                                     42
CONTD….
   Equality and Relational Operators
    Standard algebraic         C equality or   Example of C Meaning of C
    equality operator or       relational      condition    condition
    relational operator        operator
    E quality O perators
    =                          ==              x == y       x is equal to y
    not =                      !=              x != y       x is not equal to y
    R ela tiona l Op erators
    >                          >               x > y        x is greater than y
    <                          <               x < y        x is less than y
    >=                         >=              x >= y       x is greater than or
                                                            equal to y
    <=                         <=              x <= y       x is less than or
                                                                                   43
                                                            equal to y
CONTD….

   Logical Operators:
     && logical And
     || logical Or
     ! logical Not


   Bitwise Operators
    &   bitwise And
     | bitwise Or
     ^ bitwise Xor
     ~ bitwise Not
     << shift left
     >> shift right     44
SAMPLE C PROGRAM 2
/* Program for multiplication of two variables */

#include<stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“Enter two numbers”);
scanf(“%d%d”,&var1,&var2);
c=a*b;
printf (“n Multiplication of two numbers is %d ”,c);
getch();                                                45
}
CONTD…
 OUTPUT:



 Enter two numbers: 12 3
 Multiplication of two numbers is 36




                                       46
CONTROL STATEMENTS
   These statements are used to control the flow of
    program by using these statements. We can have
    four types of control statements:-

   decision making

   case control statement or switch statement

   looping / iteration statement

   jump / branching statement
                                                       47
DECISION MAKING
   These statements are used when we want to take
    any decision according to the condition or user
    requirement. These conditions are used by using
    ‘if’ statement. We can have four types of
    conditional statements

 if
 if-else

 if – else if

 nested if


                                                      48
CONTD….
 if
  if statement is simple decision making statement,
  which is used to take any decision when the
  condition is true.
 if (statement)
  {
  Statement;
  }
 if (expression / condition)

  Statement;
                                                      49
CONTD….
 If-else
 This statement is used to make decision in C
  language. If the given condition is true then the
  cursor will move to the true portion else it will
  move to the false portion.
 if (condition)
 {
Statement;
}
else
{
                                                      50
Statement;
}
    If else-if
    if (condition)
    {
    Statement;
     }
           else if (condition)
           {
                  Statement;
            }
            else if (condition)
             {
                  Statement;
              }
     else
     {                            51

           Statement;
SWITCH CASE / SELECT CASE
   These statements are used with the replacement
    of if-else and these statements are used when we
    have multiple options or choices.

   These choices can be limited and when we use
    switch case we can use only integer or character
    variable as expression.




                                                       52
   Syntax:
 switch( expression)
{
   case value-1:
        block-1;
        break;
   case value-2:
        block-2;
        break;
----
   default:
        default-block;
        break;
                         53
}
statement -X;
LOOPING
   These statements are used to control the flow of
    the program and repeat any process multiple
    times according to user’s requirement.

   We can have three types of looping control
    statements.

   while

   do-while

                                                       54
   for
CONTD…
While
 It is an entry control loop statement, because it
   checks the condition first and then if the
   condition is true the statements given in while
   loop will be executed.
 SYNTAX:-

 Initialization;
 while (condition)
 {
 Statements;
 Incremental / decrement;                             55
 }
CONTD…
Do-while

   Do-while loop is also called exit control loop.

    It is different from while loop because in this
    loop the portion of the loop is executed minimum
    once and then at the end of the loop the condition
    is being checked and if the value of any given
    condition is true or false the structure of the loop
    is executed and the condition is checked after the
    completion of true body part of the loop.              56
CONTD…
   SYNTAX:-

    Initialization
    do
     {
     Statement;
     Increment / decrement;
     }
    while (condition)
                                       57
CONTD….

For loop
 It is another looping statement or construct used
  to repeat any process according to user
  requirement but it is different from while and do-
  while loop because in this loop all the three steps
  of constructions of a loop are contained in single
  statement.

   It is also an entry control loop.

   We can have three syntaxes to create for loop:-     58
CONTD….
for (initialization; Test condition; Increment /
   decrement)
 {
 Statement;
  }
…………………………………….
for (; test condition; increment / decrement)
 {
  Statement;
  }
                                                   59
………………………………………
CONTD….
for (; test condition;)
 {
 Statement;
 Increment / decrement
 }




                                    60
JUMPS STATEMENTS
   These are also called as branching statements.

   These statements transfer control to another part
    of the program. When we want to break any loop
    condition or to continue any loop with skipping
    any values then we use these statements. There
    are three types of jumps statements.

   Continue

   Break
                                                        61
   Goto
CONTD…
   Continue
      This statement is used within the body of the
    loop. The continue statement moves control in
    the beginning of the loop means to say that is
    used to skip any particular output.

 WAP to print series from 1 to 10 and skip only 5
  and 7.
#include
void main ( )
{                                                     62

int a;
CONTD…
clrscr ( );
for (a=1; a<=10; a++)
{
if (a= =5 | | a= = 7)
continue;
printf (“%d n”,a);
}
getch ( );
}
                                 63
CONTD…

Break
 This statement is used to terminate any
  sequence or sequence of statement in switch
  statement. This statement enforce indicate
  termination. In a loop when a break statement is
  in computer the loop is terminated and a cursor
  moves to the next statement or block;
 Example:



   WAP to print series from 1 to 10 and break
    on 5
     #include
                                                     64
     void main ( )
     {
CONTD…
int a;
clrscr ( );
for (a=1; a<=10; a++)
{
if (a= =5)
break;
printf (“%d n”,a);
}
getch ( );
}                                65
CONTD…
Goto statement
 It is used to alter or modify the normal sequence
  of program execution by transferring the control
  to some other parts of the program. the control
  may be move or transferred to any part of the
  program when we use goto statement we have to
  use a label.
 Syntax:

 Forward Loop:

  goto label;
  ….
  ….
                                                      66
  label:
  statement;
CONTD…
   Backward Loop:
    label:
    statement
    ….
    ….
     goto label;




                              67
COMMON PROGRAMMING
ERRORS
 Missing Semicolons
   Eg: a = x+y …… is wrong
         c= b/d; …… is right
 Misuse of Semicolon
   Eg:
          for(i = 1; i <= 10; i++);
          sum = sum + i;
      is wrong



           for(i = 1; i <= 10; i++)
            sum = sum + i;            68
       is right
CONTD…
   Use of = instead of = =
   Missing Braces

   Missing Quotes

   Improper Comment Characters

   Undeclared Variables

     And many more……




                                  69
ASSIGNMENT
   Write a C program to swap two entered number.

   Write a C program to perform all the arithmetic
    operations.

   Write a C program to find the area of a circle,
    triangle and rectangle.

   Write a C program to calculate the area of circle,
    triangle and rectangle.

   Write a C program to get a number from user          70

    and print a square and cube of that number.
CONTD…
    Write a C program to display the greatest of
    three number using if else statement.

   Write a C program to find the number is positive
    or negative.

   Write a C program to find the number is odd or
    even.

   Write a program to display the spelling of
    number using switch case.                          71
CONTD…
    Write a C program to display the entered letter
    is vowel or a character.

   Write a C program to display odd number from 1
    to n using while loop and do while loop.

   Write a C program to display even number from
    1 to n using for loop.



                                                       72
QUERIES?


           73
THANK YOU!!!


               74

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Operators
OperatorsOperators
Operators
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Features of 'c' program
Features of 'c' programFeatures of 'c' program
Features of 'c' program
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Operation on string presentation
Operation on string presentationOperation on string presentation
Operation on string presentation
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Structure in c
Structure in cStructure in c
Structure in c
 
C functions
C functionsC functions
C functions
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 

Destacado

Overview of c language
Overview of c languageOverview of c language
Overview of c languageshalini392
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C LanguageAryan Ajmer
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingSivant Kolhe
 
control structures in c if switch for
control structures in c if switch forcontrol structures in c if switch for
control structures in c if switch forgourav kottawar
 
Comandos importantes en c++
Comandos importantes en c++Comandos importantes en c++
Comandos importantes en c++Andy Otañez
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programmingSudheer Kiran
 
Tutorial lenguaje c
Tutorial lenguaje cTutorial lenguaje c
Tutorial lenguaje ctbjs
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
Cmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowchartsCmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowchartskapil078
 
Presentation - Sudoku Assignment
Presentation - Sudoku  AssignmentPresentation - Sudoku  Assignment
Presentation - Sudoku AssignmentCj Uni
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic conceptsAbhinav Vatsa
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 

Destacado (20)

Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C Language
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
control structures in c if switch for
control structures in c if switch forcontrol structures in c if switch for
control structures in c if switch for
 
Comandos importantes en c++
Comandos importantes en c++Comandos importantes en c++
Comandos importantes en c++
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programming
 
Tutorial lenguaje c
Tutorial lenguaje cTutorial lenguaje c
Tutorial lenguaje c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
SIXTH SENSE-TECHNOLOGY
SIXTH SENSE-TECHNOLOGYSIXTH SENSE-TECHNOLOGY
SIXTH SENSE-TECHNOLOGY
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Cmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowchartsCmp104 lec 7 algorithm and flowcharts
Cmp104 lec 7 algorithm and flowcharts
 
Presentation - Sudoku Assignment
Presentation - Sudoku  AssignmentPresentation - Sudoku  Assignment
Presentation - Sudoku Assignment
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
C ppt
C pptC ppt
C ppt
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 

Similar a Introduction to c programming

Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.pptatulchaudhary821
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it worksMark John Lado, MIT
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++oggyrao
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8kapil078
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Chapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdfChapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdfKirubelWondwoson1
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxAbdalla536859
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThAram Mohammed
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 

Similar a Introduction to c programming (20)

Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it works
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C language
C languageC language
C language
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Introduction to c language
Introduction to c language Introduction to c language
Introduction to c language
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Chapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdfChapter 1 - Basic concepts of programming.pdf
Chapter 1 - Basic concepts of programming.pdf
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptx
 
Whole c++ lectures ITM1 Th
Whole c++ lectures ITM1 ThWhole c++ lectures ITM1 Th
Whole c++ lectures ITM1 Th
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Presentation 2.ppt
Presentation 2.pptPresentation 2.ppt
Presentation 2.ppt
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
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
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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
 

Introduction to c programming

  • 1. C PROGRAMMING TUTORIAL By: gajendra singh rathore
  • 2. OUTLINE  Overview  History  Features  Role of C Compiler  Flowchart  Sample C Program 1  Character Set  Data Types  Variables  C is Case Sensitive  C Token  Sample C Program 2  Control Statements  Common Programming Errors 2  Assignment
  • 3. OVERVIEW OF C  C language is  Structured  High level  Machine independent  Follows top down approach 3
  • 4. HISTORY  ALGOL  In 1960’s  First language using a block structure  BCPL  In1967  Basic Combined Programming Language  B  In1970  Added feature of BCPL 4
  • 5. CONTD…  C  Evolved from ALGOL, BCPL & B  Developed between 1969 and 1973 along with Unix  Developed at AT & T’s Bell Laboratories of USA  Designed and written by Dennis Ritchie 5
  • 6. FEATURES  C is PortableThis means a program written for one computer may run successfully on other computer also.  C is fast This means that the executable program obtained after compiling and linking runs very fast.  C is compact The statements in C Language are generally 6 short but very powerful.
  • 7. CONTD…  Simple / Easy The C Language has both the simplicity of High Level Language and speed of Low Level Language. So it is also known as Middle Level Language  C has only 32 Keywords  C Compiler is easily available  C has ability to extend itself. Users can add their own 7 functions to the C Library
  • 8. ROLE OF C COMPILER  Compiler: converts source to object code for a specific platform  Linker: resolves external references and produces the executable module  Typically C programs when executing, have four different files  Source Code – file that is created by user and the executable statements are written. This file is saved with a file extension of ‘.c’.  Header files – contains the declaration of functions and pre- processors statements. Header files have ‘.h’ as their extension.  Object files – are the output from the compilers. ‘.o’ or ‘.obj’ are the typical extension to such files. 8  Binary executables – are an output of the process of linking. Binary executables have ‘.exe’ as their extension.
  • 9. FLOWCHART  Flow charts are symbolic diagrams of operations and the sequence, data flow, control flow and processing logic in information processing.  These charts are used to understand any working sequence of the program.  Flow char is a graphical representation of algorithm.  An algorithm defines as the step by step procedure or method that can be carried out for 9 solving programming problems.
  • 10. CONTD… Advantages of flowchart:-  It provides an easy way of communication because any other person besides the programmer can understand the way they are represented.  It represents the data flow.  It provides a clear overview of the entire program and problem and solution. 10
  • 11. CONTD…  It checks the accuracy in logic flow.  It documents the steps followed in an algorithm.  It provides the facility for coding.  It provides the way of modification of running program.  They shows all major elements and their relationship. 11
  • 13. CONTD…  Terminator This symbol represents the beginning and end point in a program. We use start and stop option in it.  Input / Output Symbol This symbol is used to take any input or output in the algorithm.  Process Symbol A rectangle indicates the processing, calculation 13 and arithmetic operations
  • 14. CONTD…  Decision Symbol It is used when we want to take any decision in the program.  Connector Symbol This symbol is used to connect the various portion of a flow chart. This is normally used when the flow chart is split between two pages  Data Flow Symbol This symbol is used to display the flow of the 14 program. It shows the path of logic flow in a program.
  • 15. SAMPLE C PROGRAM main() --------------Function name { ------------Start of Program …. …. -------- Program statements …. } --------------- End of Program 15
  • 16. CONTD… /* Filename : hello.c Description : This program prints the greeting “Hello, World!” */ #include <stdio.h> #include <stdio.h> int main(void) void main( ) { { printf ( “Hello, World!n” ) ; printf ( “Hello, World!n”); return 0 ; getch(); } } 16
  • 17. FLOWCHART FOR HELLO.C An oval denotes either int main () the start or the end of { the program, or a halt printf("Hello, world!n"); } operation within the Start program (which we’ll learn about later). A parallelogram Output “Hello, world!” denotes either an input operation or an output operation. End An arrow denotes the flow of the program. 17
  • 18. CONTD…  Comments  Text surrounded by /* and */ is ignored by computer  Used to describe program  int main()  Program’s execution starts from the main function  Parenthesis used to indicate a function  int means that main "returns" an integer value  Braces ({ and }) indicate a block  The bodies of all functions must be contained in braces 18
  • 19. CONTD… o Preprocessor directives #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h>  The #include directives “paste” the contents of the files like stdio.h and conio.h into your source code, at the very place where the directives appear. 19
  • 20. CONTD…  These files contain information about some library functions used in the program:  stdio stands for “standard I/O”,  conio stands for “console I/O”  stdlib stands for “standard library”,  string.h includes useful string manipulation functions.  Want to see the files? Look in /TC/include 20
  • 21. CONTD… #define MAX_COLS 20 #define MAX_INPUT 1000  The #define directives perform “global replacements”:  every instance of MAX_COLS is replaced with 20, and every instance of MAX_INPUT is replaced with 1000 21
  • 22. CONTD…  commonly used stdio.h functions: printf() – Output function Syntax: printf(“….”) ; scanf() – Input function Syntax: scanf(“format specifier”, &var,&var2…); 22
  • 23. CONTD…  commonly used conio.h functions: clrscr() Used to clear the screen getch() Used to get a character from ouput screen to come into the edit screen. 23
  • 24. CHARACTER SET These are the characters that C recognizes. Letters (upper case and lower case) AB C DE F G H I J KLM NOPQRSTUVWXYZ abcdefghijklm nopqrstuvwxyz Digits 0123456789  Special Characters (punctuation etc) space (also known as blank) ’" ( ) * + - / : = !&$;<>%?,. ˆ#@˜‘{}[]| 24
  • 25. CONTD…  256 characters are allowed in C. A – Z : 65 to 90 26 a – z : 97 to 122 26 0 – 9 : 48 to 57 10  Special symbols[ #, &, `…] 32  Control characters[n, t . ..] 34  Graphic characters 128 Total 256 25
  • 26. DATA TYPES o C support several different types of data, which may be represented differently within the computers memory. o Types 1] Primary 2] Derived 3] User Defined  Integer  Arrays  typedef  Float  Pointers  enum  Double  Structure  Character 26
  • 27. CONTD…  Primary Data Types Data Types Byte Format Specifier 1] char 1 %c signed char 1 %c unsigned char 1 %c 2] short 2 %d short signed int 2 %d short unsigned int 2 %u 3] int 2 %d 27 signed int 2 %d unsigned int 2 %u
  • 28. CONTD… Data Types Byte Format Specifier 4] long 4 %l long signed int 4 %ld long unsigned int 4 %lu 5] float 4 %f signed float 4 %f unsigned float 4 %uf 6] double 8 %lf 28 7] Long Double 10 %Lf
  • 29. TYPE CASTING  It is used to convert on data at a time.  We can have two types of type casting.  Implicit  Explicit  Implicit : This converts narrow type to wider type so that user can avoid the information to the system.  Explicit : Explicit type casting is done by the programmer manually. When the programmer wants a result of an expression to be in particular type, then we use explicit type casting. This type casting is done by casting operators ‘( )’ 29 and data type.
  • 30. CONTD… #include <stdio.h> void main( ) { int base, height, area; base = 5; height =3; area = (base * height)/2; printf ( “Area = %d n”, area); } Output : Area = 7 ……………………. Incorrect 30
  • 31. CONTD… #include <stdio.h> void main( ) { int base, height, area; base = 5; height = 3; area = ((float) (base * height)/2); printf ( “Area = %d n”, area); } Output : Area = 7.5 …………………….Correct 31
  • 32. USER DEFINED DATA TYPE [A] Type Definition Allows user to define an identifier that would represent an existing data type Syntax: typedef type identifier Eg: typedef int units; units batch1, batch2; 32
  • 33. CONTD… [B] Enumerated data type  Syntax: enum identifier { value1, value2... valuen}  Eg: enum day{ Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday} 33
  • 34. VARIABLES  Variable names correspond to locations in the computer's memory  Data name that may be used to store a data value  It may take different values at different times during execution  Eg:  char x;  char y = ‘e’; 34
  • 35. CONTD…  Rules  Must begin with a letter(), some system permits underscore as first character.  Length should be not more than 8 characters  Uppercase and lowercase are significant, (i.e.) total and TOTAL are different  Variable should not be a keyword  White space is not allowed 35
  • 36. C IS CASE SENSITIVE C is case sensitive: it distinguishes between UPPER case (CAPITAL) and lower case (small) letters. Keywords in C — for example, the keyword int — MUST be in lower case. For example: #include <stdio.h> int main () { /* main */ int height_in_cm; height_in_cm = 160; printf("My height is %d cm.n",height_in_cm); } /* main */ 36
  • 37. C TOKENS  Keywords  Identifiers  Constants  Strings  Special Symbol  Operators 37
  • 38. CONTD…  Keywords  C uses 32 keyword  have fixed meaning and cannot be changed Keywords 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 volatile do if static while 38
  • 39. CONTD…  Constants  Quantity that does not change is called a constant.  Types  Numeric constants  Integer constants – 123, -33  Real constants – 0.992, 3.5e2  Character constants  Single character constants – ‘5’, ‘a’  String Constants – ‘Hello’, ‘1999’ 39
  • 40. CONTD… Backslash Characters Constants  n – Newline  b – Backspace  f – Form feed  t – Tab or horizontal tab  a – Audible alert  r – Carriage return  v – Vertical Tab  ’ – Single Quote  ” – Double Quote  ? – Question Mark  - Backslash 40  0 - Null
  • 41. CONTD…  Identifiers Names of arrays, function and variable  Operators Arithmetic Relational Logical Bitwise 41
  • 42. CONTD…. ARITHMETIC OPERATORS C operation Arithmetic Algebraic C expression operator expression Addition + f+7 f+7 Subtraction - p–c p-c Multiplication * bm b*m Division / x/y x/y Modulus % r mod s r % s 42
  • 43. CONTD….  Equality and Relational Operators Standard algebraic C equality or Example of C Meaning of C equality operator or relational condition condition relational operator operator E quality O perators = == x == y x is equal to y not = != x != y x is not equal to y R ela tiona l Op erators > > x > y x is greater than y < < x < y x is less than y >= >= x >= y x is greater than or equal to y <= <= x <= y x is less than or 43 equal to y
  • 44. CONTD….  Logical Operators:  && logical And  || logical Or  ! logical Not  Bitwise Operators & bitwise And  | bitwise Or  ^ bitwise Xor  ~ bitwise Not  << shift left  >> shift right 44
  • 45. SAMPLE C PROGRAM 2 /* Program for multiplication of two variables */ #include<stdio.h> #include <conio.h> void main() { int a,b,c; clrscr(); printf(“Enter two numbers”); scanf(“%d%d”,&var1,&var2); c=a*b; printf (“n Multiplication of two numbers is %d ”,c); getch(); 45 }
  • 46. CONTD…  OUTPUT: Enter two numbers: 12 3 Multiplication of two numbers is 36 46
  • 47. CONTROL STATEMENTS  These statements are used to control the flow of program by using these statements. We can have four types of control statements:-  decision making  case control statement or switch statement  looping / iteration statement  jump / branching statement 47
  • 48. DECISION MAKING  These statements are used when we want to take any decision according to the condition or user requirement. These conditions are used by using ‘if’ statement. We can have four types of conditional statements  if  if-else  if – else if  nested if 48
  • 49. CONTD….  if if statement is simple decision making statement, which is used to take any decision when the condition is true. if (statement) { Statement; }  if (expression / condition) Statement; 49
  • 50. CONTD….  If-else This statement is used to make decision in C language. If the given condition is true then the cursor will move to the true portion else it will move to the false portion. if (condition) { Statement; } else { 50 Statement; }
  • 51. If else-if if (condition) { Statement; } else if (condition) { Statement; } else if (condition) { Statement; } else { 51 Statement;
  • 52. SWITCH CASE / SELECT CASE  These statements are used with the replacement of if-else and these statements are used when we have multiple options or choices.  These choices can be limited and when we use switch case we can use only integer or character variable as expression. 52
  • 53. Syntax: switch( expression) { case value-1: block-1; break; case value-2: block-2; break; ---- default: default-block; break; 53 } statement -X;
  • 54. LOOPING  These statements are used to control the flow of the program and repeat any process multiple times according to user’s requirement.  We can have three types of looping control statements.  while  do-while 54  for
  • 55. CONTD… While  It is an entry control loop statement, because it checks the condition first and then if the condition is true the statements given in while loop will be executed.  SYNTAX:- Initialization; while (condition) { Statements; Incremental / decrement; 55 }
  • 56. CONTD… Do-while  Do-while loop is also called exit control loop.  It is different from while loop because in this loop the portion of the loop is executed minimum once and then at the end of the loop the condition is being checked and if the value of any given condition is true or false the structure of the loop is executed and the condition is checked after the completion of true body part of the loop. 56
  • 57. CONTD…  SYNTAX:- Initialization do { Statement; Increment / decrement; } while (condition) 57
  • 58. CONTD…. For loop  It is another looping statement or construct used to repeat any process according to user requirement but it is different from while and do- while loop because in this loop all the three steps of constructions of a loop are contained in single statement.  It is also an entry control loop.  We can have three syntaxes to create for loop:- 58
  • 59. CONTD…. for (initialization; Test condition; Increment / decrement) { Statement; } ……………………………………. for (; test condition; increment / decrement) { Statement; } 59 ………………………………………
  • 60. CONTD…. for (; test condition;) { Statement; Increment / decrement } 60
  • 61. JUMPS STATEMENTS  These are also called as branching statements.  These statements transfer control to another part of the program. When we want to break any loop condition or to continue any loop with skipping any values then we use these statements. There are three types of jumps statements.  Continue  Break 61  Goto
  • 62. CONTD…  Continue This statement is used within the body of the loop. The continue statement moves control in the beginning of the loop means to say that is used to skip any particular output.  WAP to print series from 1 to 10 and skip only 5 and 7. #include void main ( ) { 62 int a;
  • 63. CONTD… clrscr ( ); for (a=1; a<=10; a++) { if (a= =5 | | a= = 7) continue; printf (“%d n”,a); } getch ( ); } 63
  • 64. CONTD… Break  This statement is used to terminate any sequence or sequence of statement in switch statement. This statement enforce indicate termination. In a loop when a break statement is in computer the loop is terminated and a cursor moves to the next statement or block;  Example:  WAP to print series from 1 to 10 and break on 5 #include 64 void main ( ) {
  • 65. CONTD… int a; clrscr ( ); for (a=1; a<=10; a++) { if (a= =5) break; printf (“%d n”,a); } getch ( ); } 65
  • 66. CONTD… Goto statement  It is used to alter or modify the normal sequence of program execution by transferring the control to some other parts of the program. the control may be move or transferred to any part of the program when we use goto statement we have to use a label.  Syntax:  Forward Loop: goto label; …. …. 66 label: statement;
  • 67. CONTD…  Backward Loop: label: statement …. …. goto label; 67
  • 68. COMMON PROGRAMMING ERRORS  Missing Semicolons  Eg: a = x+y …… is wrong c= b/d; …… is right  Misuse of Semicolon  Eg: for(i = 1; i <= 10; i++); sum = sum + i;  is wrong for(i = 1; i <= 10; i++) sum = sum + i; 68  is right
  • 69. CONTD…  Use of = instead of = =  Missing Braces  Missing Quotes  Improper Comment Characters  Undeclared Variables And many more…… 69
  • 70. ASSIGNMENT  Write a C program to swap two entered number.  Write a C program to perform all the arithmetic operations.  Write a C program to find the area of a circle, triangle and rectangle.  Write a C program to calculate the area of circle, triangle and rectangle.  Write a C program to get a number from user 70 and print a square and cube of that number.
  • 71. CONTD…  Write a C program to display the greatest of three number using if else statement.  Write a C program to find the number is positive or negative.  Write a C program to find the number is odd or even.  Write a program to display the spelling of number using switch case. 71
  • 72. CONTD…  Write a C program to display the entered letter is vowel or a character.  Write a C program to display odd number from 1 to n using while loop and do while loop.  Write a C program to display even number from 1 to n using for loop. 72
  • 73. QUERIES? 73