ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ

Click here to load reader

  • date post

    14-Apr-2017
  • Category

    Education

  • view

    2.503
  • download

    1

Embed Size (px)

Transcript of ΓΛΩΣΣΑ C - ΜΑΘΗΜΑ 4 - ΤΕΛΕΣΤΕΣ και η ΔΟΜΗ ΕΛΕΓΧΟΥ

  • H C

    4:

    (if$else)

  • .

    1. C

    1.

    2.

    2.

    3.

    1.

    2.

    3.

    4.

    1.

    2.

    5.

    1.

    2.

    6.

    7.

    2 , C, 4: (if...else)

    B.

    1.

    2. ( if)

    3. (if...else)

    4.

    5. (if;else

    if;else)

    6.

    7. ; ?:

    .

  • A. 1. C 1.

    3 , C, 4: (if...else)

    3

    :

    (.. x,y,z)

    (

    )

    (.. 5, 8.0, 3.2543)

    (

    ( . ) )

    (.. PI, N)

    ( #define const)

  • A. 1. C 2.

    4 , C, 4: (if...else)

    ,

    :

    ( . +

    / )

    :

    ( ..

  • A. 2.

    5 , C, 4: (if...else)

    () ( = )

    :

    :

    (

    , )

    _

    :

    () x 5.

    () x 4.

    _ = ;

    x=1+4;

    x=16/(3+1);

  • A. 3. 1.

    6 , C, 4: (if...else)

    :

    ( )!

    + + x+y

    / * * x*y

    - - x-y

    / / x/y

    % % x%y

  • A. 3. 1.

    7 , C, 4: (if...else)

    prakseis.c

    ,

    if$else if$else ( == ).

    , .. 7/3.

    2!!

    ( ).

  • A. 3. 1.

    8 , C, 4: (if...else)

    /* prakseis.c: Anadeiknyei tin xrisi twn dimelwn mathimatikwn praksewn */ #include

    main()

    {

    int x,y,z;

    int telestis;

    printf("\nDwste ton 1o akeraio: ");

    scanf("%d",&x);

    printf("Dwste ton 2o akeraio: ");

    scanf("%d",&y);

    printf("Dwste ton telesti\n 0 gia +\n 1 gia -\n 2 gia /\n 3 gia *\n 4 gia %");

    printf("\nEpilogi? ");

    scanf("%d",&telestis);

    if (telestis==0)

    {

    z=x+y;

    printf("%d+%d=%d",x,y,z);

    }

    else if (telestis==1)

    {

    z=x-y;

    printf("%d-%d=%d",x,y,z);

    }

  • A. 3. 1.

    9 , C, 4: (if...else)

    else if (telestis==2) { z=x*y;

    printf("%d*%d=%d",x,y,z);

    }

    else if (telestis==3)

    {

    z=x/y;

    printf("%d/%d=%d",x,y,z);

    }

    else if (telestis==4)

    {

    z=x%y;

    printf("%d\%%d=%d",x,y,z);

    }

    }

  • A. 3. 2.

    10 , C, 4: (if...else)

    2: ++ -- ,

    1 1.

    .

    2 :

    ( )

    ( )

    ++ ++

    ++

    i++

    ++j

    --

    --

    i

    --i

    --j

  • A. 3. 2.

    11 , C, 4: (if...else)

    :

    :

    x++;

    :

    :

    x--;

    ++x;

    x=x+1;

    x++;

    ++x;

    x=x+1;

    x++;

  • A. 3. 2.

    12 , C, 4: (if...else)

    1 .

    .. :

    2 :

    x 1, x 2.

    y 2.

    ( ++),

    .

    .. :

    2 :

    y 1

    x=1;

    y=++x;

    x=1;

    y=x++;

  • A. 3. 2.

    13 , C, 4: (if...else)

    ,

    !

    /*monadiaioi.c: Anadeikniei tin leitoyrgia twn monadiaiwn telestwn*/

    #include

    main()

    {

    int x=1;

    int y=1;

    printf("%d,%d",x++,++y);

    printf("\n%d,%d",x++,++y);

    printf("\n%d,%d",x++,++y);

    printf("\n%d,%d",x,y);

    }

  • A. 3. 3.

    14 , C, 4: (if...else)

    , ,

    , ,

    mod,

    ,

    !

    .. :

    :

    1. ++,--

    2. *, / , %

    3. +, -

    z=x+y/x-y

    z=(x+(y/x))-y

    :

    !

  • A. 4. 1.

    15 , C, 4: (if...else)

    1 ( ) 0 ( )

    :

    == == x==y

    > > x>y

    >= >= x>=y

    <

  • A. 4. 1.

    16 , C, 4: (if...else)

    :

    8+1==9

    : 1 ()

    6*2==5+4+3

    : 1 ()

    5%2 != 5/2

    : 0 ()

    7>9

    : 0 ()

    !

    ,

    0 1. .. :

    z 1.

    z=(1

  • A. 4. 1.

    17 , C, 4: (if...else)

    :

    if$else$ ,

    .

    0 1.

    ;

    x=(x!=x)

  • A. 4. 1.

    18 , C, 4: (if...else)

    ,

    !

    /*sxesiakoi.c: Anadeikniei tin leitoyrgia twn sxesiakwn telestwn*/

    #include

    main()

    {

    int x=1;

    int y=2;

    int z;

    z=(x>y);

    printf("\nx>y:%d",z);

    z=(x>=y);

    printf("\nx>=y:%d",z);

    z=(x==y);

    printf("\nx==y:%d",z);

    z=(x

  • A. 4. 2.

    19 , C, 4: (if...else)

    . .

    :

    .

    .. :

    :

    :

    1. =

    2. !=,==

    (1

  • A. 5. 1.

    20 , C, 4: (if...else)

    AND, OR :

    0 1 (

    )

    (=1) (=0)

    AND && 1 && 2 1 (1)

    2 (1)

    1 (1)

    2 (1)

    OR || 1 || 2 1 (1)

    2 (1)

    1 (0)

    2 (0)

    NOT ! ! (0) (1)

    : C 0,

    0.

  • A. 5. 1.

    21 , C, 4: (if...else)

    :

    (5

  • A. 5. 2.

    22 , C, 4: (if...else)

    , . ( ) :

    ,

    .

    1. !

    2. &&

    3. ||

  • A. 5. 2.

    23 , C, 4: (if...else)

    ,

    !

    /* logikoi.c: Anadeikniei tin leitoyrgia twn logikwn telestwn */

    #include

    main()

    {

    int x=1;

    int y=2;

    int z;

    z=(y>x) && (x

  • A. 6. 1.

    24 , C, 4: (if...else)

    , :

    :

    += += x+=5; x=x+5;

    -= -= x-=2; x=x-2;

    /= /= x/=y; x=x/y;

    / *= *= x*=a+b; x=x*(a+b)

    Modulo %= MET%= x%=8; x=x%8;

  • A. 7.

    25 , C, 4: (if...else)

    :

    : *, ->, &

    bytes: &, | ^

    : >>

  • A. 7.

    26 , C, 4: (if...else)

    1. () [] -> .

    2. ! ++ -- * & (type) sizeof + -

    3. * / %

    4. + -

    5. >

    6. < >=

    7. == !=

    8. &

    9. ^

    10. |

    11. &&

    12. ||

    13. ?:

    14. = += -= *= /= %= &= ^= |= =

    15. ,

  • B. 1.

    27 , C, 4: (if...else)

    , .

    (if)

    .

    .

    ,

    .

    .

    .

  • B. 2. : if

    28 , C, 4: (if...else)

    1 :

    (

    / )

    1

    ( )

    (

    )

    [ ]

    if ()

    1;

    [ ] 1

    [ ]

    [ ]

  • B. 2. : if

    29 , C, 4: (if...else)

    , ,

    [ ]

    if ()

    {

    1;

    2;

    ;

    }

    [ ]

    1;

    2;

    ;

    [ ]

    [ ]

    !

    ,

    ! (

    )

  • B. 2. : if

    30 , C, 4: (if...else)

    1: if,

    !

    if

    if (x>y);

    {

    x=x+1;

    y=y+2;

    }

    !

    2: if .

    .

    .

  • B.

    31 , C, 4: (if...else)

    /* if_01.c: Deixnei tin xrisi tis if */

    #include

    main()

    {

    int x;

    int y;

    printf("Dwste ton akeraio x: ");

    scanf("%d",&x);

    printf("Dwste ton akeraio y: ");

    scanf("%d",&y);

    if (x=y)

    printf("\n%d>=%d",x,y);

    }

    ,

    1

    if

    ;

  • B. 3. : if$else

    32 , C, 4: (if...else)

    , 2 :

    (

    / )

    ( )

    ( )

    [ ]

    if ()

    ;

    else

    ;

    [ ]

    A

    [ ]

    [ ]

    B

  • B. 3. : if$else

    33 , C, 4: (if...else)

    if else,

    :

    [ ]

    if ()

    {

    _1;

    ...

    _;

    }

    else

    {

    _1;

    ...

    _N;

    }

    [ ]

    A1 A2 $

    AN

    [ ]

    [ ]

    B1 B2 $

    BN

  • , 1

    if

    ;

    34 , C, 4: (if...else)

    /* if_02.c: Deixnei tin xrisi tis if..else */

    #include

    main()

    {

    int x;

    printf("Dwste enan akeraio: ");

    scanf("%d",&x);

    if(x%2==0)

    printf("O arithmos einai artios!");

    else

    printf("O arithmos einai perittos!");

    }

    B. 3. : if$else

  • B. 3. : if$else

    35 , C, 4: (if...else)

    if$else ( ):

    .

    [$] else ,

    , .

    :

    ().

    if ()

    [else

    ]

  • B. 4.

    36 , C, 4: (if...else)

    ! .. if

    if

    .

    ;

    /* if_03.c: Deixnei tin xrisi tis if */

    #include

    main()

    {

    int x;

    int y;

    printf("Dwste ton akeraio x: ");

    scanf("%d",&x);

    printf("Dwste ton akeraio y: ");

    scanf("%d",&y);

    if(x

  • B. 5. : if$else if $ else

    37 , C, 4: (if...else)

    3

    .

    :

    [ ]

    if ( )

    {

    ()

    }

    else if ( )

    {

    ()

    }

    else

    {

    ()

    }

    [ ]

    [ ]

    [ ]

  • B. 6.

    38 , C, 4: (if...else)

    ..

    .

    ,

    , switch

    .

    .

    [ ]

    if ( )

    {

    (1)

    }

    else if ( )

    {

    (2)

    }

    else if ()

    {

    ()

    }

    else

    {

    (+1)

    }

    [ ]

  • B. 6.

    39 , C, 4: (if...else)

    [ ]

    if (1)

    {

    (1)

    }

    else if (2)

    {

    (2)

    }

    else if ()

    {

    ()

    }

    else

    {

    (+1)

    }

    [ ]

    1 1

    [ ]

    2 2

    +1

    [ ]

    $

    $ $

  • B. 7. $ ?:

    40 , C, 4: (if...else)

    ( ) if$else$

    :

    ?: :

    ( ) ?:

    !

    if ()

    else

    ? :

  • B. 7. $ ?:

    41 , C, 4: (if...else)

    /* ternary.c:Eksereuna ton telesti ?: */ #include

    main()

    {

    int x,y,z;

    /* Kai i if epistrefei mia timi */

    x=0; y=1;

    if(x

  • . 1

    42 , C, 4: (if...else)

    C

    (65)

  • . 2

    43 , C, 4: (if...else)

    C

    2.

  • . 3

    44 , C, 4: (if...else)

    C

    3.

  • . 4

    45 , C, 4: (if...else)

    C

    .

    :

    Eisagete ton 1o arithmo: 8

    Eisagete ton 2o arithmo: 5

    Eisagete ton 3o arithmo: 9

    H diataksi einai: 5,8,9

  • . 5

    46 , C, 4: (if...else)

    C

    ,

    .

    ,

    .

    1000:

    :

    / %

    !

    Eisagete plithos deyteroleptwn: 5000

    Wres: 1

    Lepta: 23

    Deyterolepta: 20

  • . 6

    47 , C, 4: (if...else)

    ()

    ( ) .

    C

    ( )

    .

  • . 7

    48 , C, 4: (if...else)

    :

    4

    100 400 .

    C

    .

    4

    :

    :

    x .. 4,

    x 4 0.

    Eisagete etos: 2018

    Einai Disekto!

    Eisagete etos: 2000

    Einai Disekto!

    Eisagete etos: 2100

    Den einai Disekto!

    Eisagete etos: 2021

    Den einai Disekto!