computing lec 3

download computing lec 3

of 180

Transcript of computing lec 3

  • 7/27/2019 computing lec 3

    1/180

    C-Language

    CS 535 Introduction to Scientific Computing

    Theory : 3rdLecture

  • 7/27/2019 computing lec 3

    2/180

    History

    A brief mention:

    Computer Language :

    Low level : Machine language

    Middle level : Assembly language

    High Level : C, Java, Fortran, so many

    So C is a high level language

    Designed by

  • 7/27/2019 computing lec 3

    3/180

    Every language has a set of

    symbols

  • 7/27/2019 computing lec 3

    4/180

    Cs Character Set

  • 7/27/2019 computing lec 3

    5/180

    Cs Character Set

  • 7/27/2019 computing lec 3

    6/180

    Every language has a set of

    symbolsSymbols are only for creating

    words

  • 7/27/2019 computing lec 3

    7/180

    Cs Words : Identifiers

  • 7/27/2019 computing lec 3

    8/180

    Cs Words : Identifiers

  • 7/27/2019 computing lec 3

    9/180

    Cs Words : Identifiers

  • 7/27/2019 computing lec 3

    10/180

    Every language has a set of

    symbols

    Symbols are only for creating

    words

    Some words are called proper nouns

    with a distinction of their own

  • 7/27/2019 computing lec 3

    11/180

    Cs Key words

  • 7/27/2019 computing lec 3

    12/180

    Cs Key words

  • 7/27/2019 computing lec 3

    13/180

    My resolution is constant; will

    not change till the end of this life

  • 7/27/2019 computing lec 3

    14/180

    Cs Constants

  • 7/27/2019 computing lec 3

    15/180

    Numeric constants Rules

  • 7/27/2019 computing lec 3

    16/180

    Integer Numeric constants Rules

  • 7/27/2019 computing lec 3

    17/180

    Decimal Integer constants Rules

  • 7/27/2019 computing lec 3

    18/180

    Octal Integer constants Rules

  • 7/27/2019 computing lec 3

    19/180

    Hexadecimal Integer constants Rules

  • 7/27/2019 computing lec 3

    20/180

    Hexadecimal Integer constants Rules

  • 7/27/2019 computing lec 3

    21/180

    Floating Point constants Rules

  • 7/27/2019 computing lec 3

    22/180

    Floating Point constants Rules

  • 7/27/2019 computing lec 3

    23/180

    Character constants Rules

  • 7/27/2019 computing lec 3

    24/180

    Character constants Rules

  • 7/27/2019 computing lec 3

    25/180

    String constants Rules

    characters that are embedded within the string

  • 7/27/2019 computing lec 3

    26/180

    Symbolic constants Rules

    correspondingcharacter sequence

  • 7/27/2019 computing lec 3

    27/180

    Symbolic constants Rules

  • 7/27/2019 computing lec 3

    28/180

    The price is variable quantity, so it

    may change its values in the market

  • 7/27/2019 computing lec 3

    29/180

    Variables

  • 7/27/2019 computing lec 3

    30/180

    Escape Sequence

  • 7/27/2019 computing lec 3

    31/180

    Escape Sequence

    null \0 000

  • 7/27/2019 computing lec 3

    32/180

    Data Types

  • 7/27/2019 computing lec 3

    33/180

    Data Types

  • 7/27/2019 computing lec 3

    34/180

    Variable Declaration

  • 7/27/2019 computing lec 3

    35/180

    Examples Variable Declaration

  • 7/27/2019 computing lec 3

    36/180

    Examples Variable Declaration

    declaration

  • 7/27/2019 computing lec 3

    37/180

    Initializing Variable

  • 7/27/2019 computing lec 3

    38/180

    Initializing Variable

    initially assigned the character *

  • 7/27/2019 computing lec 3

    39/180

    Type Conversion

  • 7/27/2019 computing lec 3

    40/180

    Examples : Type Conversion

  • 7/27/2019 computing lec 3

    41/180

    Examples : Type Conversion

  • 7/27/2019 computing lec 3

    42/180

    Examples : Type Conversion

  • 7/27/2019 computing lec 3

    43/180

    Examples : Type Conversion

  • 7/27/2019 computing lec 3

    44/180

    Examples : Type Conversion

  • 7/27/2019 computing lec 3

    45/180

    Examples : Type Conversion

  • 7/27/2019 computing lec 3

    46/180

    Operators

  • 7/27/2019 computing lec 3

    47/180

    Types of Operators

  • 7/27/2019 computing lec 3

    48/180

    Arithmetic Operators

    Modulus operator

  • 7/27/2019 computing lec 3

    49/180

    Arithmetic Operators

  • 7/27/2019 computing lec 3

    50/180

    Arithmetic Operators : Examples

    expression

  • 7/27/2019 computing lec 3

    51/180

    Arithmetic Operators : Examples

  • 7/27/2019 computing lec 3

    52/180

    Arithmetic Operators : Examples

  • 7/27/2019 computing lec 3

    53/180

    Arithmetic Operators : Conversion

  • 7/27/2019 computing lec 3

    54/180

    Arithmetic Operators : Conversion

  • 7/27/2019 computing lec 3

    55/180

    Arithmetic Operators : Conversion

  • 7/27/2019 computing lec 3

    56/180

    Arithmetic Operators : Conversion

  • 7/27/2019 computing lec 3

    57/180

    Type Conversion summary

    long doubledoublefloatunsigned long longlong long

    unsigned longlongunsigned intintunsigned shortshortunsigned charchar

    Higher

    Lower

  • 7/27/2019 computing lec 3

    58/180

    Unary Operators

  • 7/27/2019 computing lec 3

    59/180

    Unary Operators

  • 7/27/2019 computing lec 3

    60/180

    Unary Operators

  • 7/27/2019 computing lec 3

    61/180

    Unary Operator : Example

  • 7/27/2019 computing lec 3

    62/180

    Unary Operator : Example

  • 7/27/2019 computing lec 3

    63/180

    Unary Operator : Example

  • 7/27/2019 computing lec 3

    64/180

    Unary Operator : Example

  • 7/27/2019 computing lec 3

    65/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    66/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    67/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    68/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    69/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    70/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    71/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    72/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    73/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    74/180

    Relational & Logical Operators

  • 7/27/2019 computing lec 3

    75/180

    Assignment Operators

  • 7/27/2019 computing lec 3

    76/180

    Assignment Operators

  • 7/27/2019 computing lec 3

    77/180

  • 7/27/2019 computing lec 3

    78/180

    Assignment Operators

  • 7/27/2019 computing lec 3

    79/180

    Assignment Operators

    value of the conditional expression

  • 7/27/2019 computing lec 3

    80/180

    i O

  • 7/27/2019 computing lec 3

    81/180

    Assignment Operators

    Other assignment operators: C also has five additional assignment operators:

    +=, -+, *=, /=, and%=

    To see how they work, consider the first

    operator +=. The assignment expression :

    Expression 1 += Expression-2

    is equivalent to :

    Expression 1 = Expression 1 + Expression 2

    Bi i O

  • 7/27/2019 computing lec 3

    82/180

    Bitwise Operators

    L f Shif O

  • 7/27/2019 computing lec 3

    83/180

    Left Shift Operator

  • 7/27/2019 computing lec 3

    84/180

    S i l O t

  • 7/27/2019 computing lec 3

    85/180

    Special Operators

    A i ti it & P d

  • 7/27/2019 computing lec 3

    86/180

    Associativity & Precedence

    A i ti it & P d

  • 7/27/2019 computing lec 3

    87/180

    Associativity & Precedence

    A i ti it & P d

  • 7/27/2019 computing lec 3

    88/180

    Associativity & Precedence

    P ti P bl

  • 7/27/2019 computing lec 3

    89/180

    Practice Problems

    I t d O t t

  • 7/27/2019 computing lec 3

    90/180

    Input and Output

    I t d O t t

  • 7/27/2019 computing lec 3

    91/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    92/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    93/180

    Input and Output

  • 7/27/2019 computing lec 3

    94/180

    Input and Output

  • 7/27/2019 computing lec 3

    95/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    96/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    97/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    98/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    99/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    100/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    101/180

    Input and Output

  • 7/27/2019 computing lec 3

    102/180

    Input and Output

  • 7/27/2019 computing lec 3

    103/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    104/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    105/180

    Input and Output

  • 7/27/2019 computing lec 3

    106/180

    Input and Output

  • 7/27/2019 computing lec 3

    107/180

    Input and Output

    have been entered successfully.

    Input and Output

  • 7/27/2019 computing lec 3

    108/180

    Input and Output

  • 7/27/2019 computing lec 3

    109/180

    Input and Output

  • 7/27/2019 computing lec 3

    110/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    111/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    112/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    113/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    114/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    115/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    116/180

    Input and Output

  • 7/27/2019 computing lec 3

    117/180

    Input and Output

  • 7/27/2019 computing lec 3

    118/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    119/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    120/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    121/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    122/180

    Input and Output

    Input and Output

  • 7/27/2019 computing lec 3

    123/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    124/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    125/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    126/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    127/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    128/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    129/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    130/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    131/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    132/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    133/180

    p p

    Input and Output

  • 7/27/2019 computing lec 3

    134/180

    Input and Output

  • 7/27/2019 computing lec 3

    135/180

    Input and Output

  • 7/27/2019 computing lec 3

    136/180

    Input and Output

  • 7/27/2019 computing lec 3

    137/180

    Input and Output

  • 7/27/2019 computing lec 3

    138/180

    Input and Output

  • 7/27/2019 computing lec 3

    139/180

    conversion character

    Input and Output

  • 7/27/2019 computing lec 3

    140/180

    Input and Output

  • 7/27/2019 computing lec 3

    141/180

    Input and Output

  • 7/27/2019 computing lec 3

    142/180

    Input and Output

  • 7/27/2019 computing lec 3

    143/180

    Input and Output

  • 7/27/2019 computing lec 3

    144/180

    Control Structures

  • 7/27/2019 computing lec 3

    145/180

    Control Structures

  • 7/27/2019 computing lec 3

    146/180

    Control Structures

  • 7/27/2019 computing lec 3

    147/180

    statement will be ignored

    Control Structures

  • 7/27/2019 computing lec 3

    148/180

    Control Structures

  • 7/27/2019 computing lec 3

    149/180

    Control Structures

  • 7/27/2019 computing lec 3

    150/180

    Control Structures

  • 7/27/2019 computing lec 3

    151/180

    Control Structures

  • 7/27/2019 computing lec 3

    152/180

    Control Structures

  • 7/27/2019 computing lec 3

    153/180

    Control Structures

  • 7/27/2019 computing lec 3

    154/180

    Control Structures

  • 7/27/2019 computing lec 3

    155/180

    Control Structures

  • 7/27/2019 computing lec 3

    156/180

    Control Structures

  • 7/27/2019 computing lec 3

    157/180

    Control Structures

  • 7/27/2019 computing lec 3

    158/180

    Control Structures

  • 7/27/2019 computing lec 3

    159/180

    Control Structures

  • 7/27/2019 computing lec 3

    160/180

    Control Structures

  • 7/27/2019 computing lec 3

    161/180

    Control Structures

  • 7/27/2019 computing lec 3

    162/180

    Control Structures

  • 7/27/2019 computing lec 3

    163/180

    Control Structures

  • 7/27/2019 computing lec 3

    164/180

    Control Structures

  • 7/27/2019 computing lec 3

    165/180

    Control Structures

  • 7/27/2019 computing lec 3

    166/180

    Control Structures

  • 7/27/2019 computing lec 3

    167/180

    Control Structures

  • 7/27/2019 computing lec 3

    168/180

    Control Structures

  • 7/27/2019 computing lec 3

    169/180

    Control Structures

  • 7/27/2019 computing lec 3

    170/180

    Control Structures

  • 7/27/2019 computing lec 3

    171/180

    Control Structures

  • 7/27/2019 computing lec 3

    172/180

  • 7/27/2019 computing lec 3

    173/180

    Repetition Statement :for

  • 7/27/2019 computing lec 3

    174/180

    For Loop:

    for (initialisation; repetition_condition; update)

    {

    Statement1;

    ... ...

    StatementN;

    }

    Execution Details:

    (1) it executes the initialisationstatement.

    (2) it checks to see if repetition_conditionis true. If it isn't, it finishes

    with the "for loop" completely. But if it is, it executes each of thestatements Statement1... StatementNin turn, and then executesthe expression update.

    (3) After this, it goes back to the beginning of step (2) again.

    Repetition Statement :for loop

  • 7/27/2019 computing lec 3

    175/180

    Repetition Statement : whileloop

  • 7/27/2019 computing lec 3

    176/180

    Repetition Statement :do-whileloop

  • 7/27/2019 computing lec 3

    177/180

    do-while loop:do{statement 1;

    statement 2;

    ..statement n;

    }while(condition);

    Execution Details:Same as while loop. Only difference is that condition is

    checked at the end. So the set of statements must be executedat least once.

    Practice Problems

  • 7/27/2019 computing lec 3

    178/180

  • 7/27/2019 computing lec 3

    179/180

  • 7/27/2019 computing lec 3

    180/180