of 587/587
Σημειώσεις και διαφάνειες από το Μάθημα: Πληροφορική ΙΙ ΠΑΝΕΠΙΣΤΗΜΙΟ ΑΘΗΝΩΝ ΤΜΗΜΑ ΜΑΘΗΜΑΤΙΚΩΝ

Σημειώσεις και Διαφάνειες από το μάθημα Πληροφορική ΙΙ.pdf

  • View
    11

  • Download
    4

Embed Size (px)

Text of Σημειώσεις και Διαφάνειες από το μάθημα Πληροφορική...

  • :

  • C. 1. MinGW "MinGW-3.1.0-1.exe" ( next..) ( cd http://mesh.dl.sourceforge.net/sourceforge/mingw/MinGW-3.1.0-1.exe ( windows) 2. : start -> Control Panel -> System -> Advanced -> Environment Variables 3. "System variables" path . 4. ;C:\MinGW\bin . compiler: 5. : start -> All Programs -> Accessories -> Command Prompt (E : : start -> Run "cmd") 6.M Command Prompt (c.p.) C:\Documents and Settings\username>

  • 7.M c.p. : - : "cd.." C:\Documents and Settings> -N : "cd username" C:\Documents and Settings\username> , . 8. ( ...) C:\ : C:\progs 9. windows ls -> Folder Options -> View - "Hide extensions for known file types" .. 10. C:\progs , -> New -> Text Document 11. hello.c 12. notepad . : #include main() { printf("Aloha! Doulevei!"); }

  • 13. . 14. c.p. ("cd.." enter "cd.." enter "cd progs" enter) 15.: "gcc -o hello.exe hello.c" compiling 16. , "hello" c.p.

    ZiP

  • .

    & . & / / / .

  • .

    /

  • /

    -

    .

  • parallel.di.uoa.gr/students (, ) : . , .

    / : . , .

    :

    10 12

    10 12 -

    10 - 12 -

    :

  • : 15 - 10 - 2001

    C.

    .

    / (20%) .

    >= 5

    = 0.8* + 0.2 *

    (

  • C

    . :

    parallel.di.uoa.gr\students

  • C

  • 1642 B. Pascal - 1792-1871 Charles Babbage

    1944 / Harvard Mark I- 1

    1946 / - ENIAC- 1

  • 1951 UNIVAC 1946-1953 1 - 1953-1963 2 - 1963-1975 3 -

    1975-1985 4

  • 1986-2000 5

    2000-2010 6 ?

  • / :

    .

    / (special purpose)

    / (general purpose)

  • : , , ,

    : ,

    1 32 4

    5 6

    100 40

  • : , , (CD)

  • Abu Jafar Mohammed ibn Musa al Khowarizmi (825 )Liber algorithmi

    (programming languages) (machine language) Assembly (PL1) (C, C++, Java, Pascal, Fortran,Basic, Cobol, Ada)

  • (compiler) (source program) (syntax errors) (object code) (execution errors)

  • (source)

    (object)

    (Executable)

    ?

    .c

    .obj

    .exe

    ?

  • (system software) (Operating System)1. 2. 3.

    4. - (Pascal, C, C++,Java, Fortran,

    Basic, Cobol)

  • (preprocessors) (linkers) (text processors)

    (applications software) () (application packages) (program libraries)

  • C

    Dennis Ritchie (1970)UNIX

    1989 Ansi C

  • C

    1.

    2.

    3.

    4. ()5. main

    6.

  • //

    /* */

  • #include

    stdio.h, - C, .

  • #include arxeio.h

    arxeio.h, (directory), .

  • (DIRECTORIES)

    \

    grammata paixnidi ergasies

    aygoustos programata

    C:ergasies\programata

  • .

  • main

    int main ( void ){

    _1

    _2

    _

    return 0;

    }

  • main

    C main.

    main :

    return 0;

    main.

  • C

    C .

  • \* *\

    #include

    int main (void){

    \* *\double x1, x2, x3, athroisma, mesi_timi;

    printf(\n :);scanf(%lf %lf %lf , &x1, &x2, &x3);printf(\n :);

  • printf(%5.3f %5.3f %5.3f , x1, x2, x3);\* *\

    athroisma = x1 + x2 + x3;

    \* *\

    mesi_timi = athroisma / 3.0;

    \*E *\

    printf(\n : %5.3f, mesi_timi);return 0;

    }

  • C

    : a b c d . . . z

    : A B C D . . . Z

    : 0 1 2 3 4 5 6 7 8 9

    : =, ==, !=, &, &&, +, ++,/, -, --

    *, +=, _=, *=, /=, %, ||, : auto, break, case, char, default,do, double, else, enum, extern, float, int, if, for,while, return, short, sizeof,struct, switch, void,typedef, union, static

  • C , _.

    _.

    athroisma_1 xaraktiras x1 y1

    x + y

  • (integer)-9 +340 0 7550

    1,76 076

    (floating point)( ) () ( )

    123.6 .456 13. 0.0 0.

    0.123 x 102

    0.1232 0.123e2

  • ASCII 128

    EBCDIC 256

    byte .

    a 97 A 65 0 48

    b 98 B 66 1 49

    c 99 C 67 2 50

  • (escape characters) C

    (NULL) \0 0 (new line) \n 10

    (Carriage Return) \r 13 \ 34

    \ 39

    \\ 92

  • : . , . , .

  • .

    :

    1.(built-in) 2.

    ( ) :

    1. (fundamental) 2. (derived)

  • Integer

    Signed

    Short integer (short, short int, signed short,signed short int) 16 bits

    Integer (int, signed, signed int) Long integer (long, long int, signed long,

    signed long int )

  • Unsigned

    Short integer (unsigned short,unsigned short int)Integer (unsigned, unsigned int)

    Long integer (unsigned long, unsigned long int )Floating point

    floating point (float) double floating point (double)

    long double floating point (long double)(96,128)Character(char) 8 bits

  • short int int [-215, 215-1]=[-32768,32767]int (32 bits ) [-231 , 231-1]=[-2.147.483.648, ]-L* * * * * ****-s 0 s**** * * * * * * * *L

    .

    ()

  • 1) #define #define PI 3.1415927

    #define MHDEN 1e-20

    #define N 200

    2) const - = ;const double PI = 3.1415927;

    const float MHDEN = 1e-20;

    const int N=200;

  • ;

    : int, float, double, char

    : .

    int i, j;char xar_1, xar_2;

    float max, x, y;

  • - ++ -- 1

    * / % 2

    + - 3

  • y * y / 2 * z 1 / x ( ):

    a. y * yb. y * y / 2c. y * y / 2 * zd. 1 / xe. y * y / 2 * z 1 / x

  • C

    k k/l

    l

    z + (x mod y) z + x % ya + b (a + b)/(c + d)c + d

    a2 4bc a*a 4 * b * c

  • 2 % 7 2

    2 / 7 0

    12 % 3 0

    12 / 3 4

    12 / 9 1

    12 % 9 3

    n % 2 1, n

    0, n

  • z (a + b / 2) + w * y :

    a. b / 2

    b. a + b / 2

    c. w * y

    d. z (a + b / 2)e. z (a + b / 2) + w * y

  • ( ) = ;

    double x, y, mean, diff ;

    x = 1.0 ;

    y = 2.0 ;

    / , .

  • mean = (x + y) / 2.0;diff = x y ;

    ( )H

    = ;

    = ;

  • int x =8; y=15;

    y += x ; 23

    y -= x ; 7

    y /= x; 1

    y %= x ; 7

    H y *= x+5 ; y = y * (x+5);

  • ++i; i++ ;

    i = i + 1;

    ++i , ++i .

    i i++ .

  • protos =3;

    metritis = protos++;

    metritis 3.

    protos = 3;

    metritis = ++protos;

    metritis 4.

  • .

    1. double, double.

    2. int, int.

    3. .

  • double x=3.2;

    int y = 5;

    x = x + y ;

    x 8.2 (double) y = x + y ;

    y 8 (int)

  • (casting)

    () .

    double protos = 3.8 ;

    int deyteros = 9 ;

    (int) (protos + deyteros); 12protos=(int)protos + deyteros; 12.0protos=(int)protos % deyteros; 3.0protos=deyteros % (int)protos; 0.0

  • .

    int, unsigned short, short

  • , .

    double d; int i; float f;

    d = f; ( )f= d; ( , d )i=d; ( ,

    d).

  • double math.h, (int) stdio.h. x,y /ceil(x) double x intfloor double x int

    abs(x) int | x | intfabs double | x | doublesqrt(x) double x (x 0) doublepow(x,y) double xy double

  • x,y /

    cos(x) double(radians) cos(x) doublesin(x) double(radians) sin(x) doubletan(x) double >> tan(x) doubleexp(x) double ex doublelog(x) double lnx doublelog10(x) double logx double

  • ceil(5.3) 6floor(6.9) 6abs(-8) 8fabs(-7.3) 7.3sqrt(4) 2.0pow(3,2) 9.0sin(30 * 3.141593/180) 0.5exp(2.1) 8.16617log(2) 0.693147log10(2) 0.30103

  • :

    ax2 + bx + c = 0

    diakrinousa = b * b 4 * a * c;

    riza_1 = (-b + sqrt(diakrinousa)) / (2*a);riza_2 = (-b - sqrt(diakrinousa)) / (2*a);

    2 3 1

  • (relational operators) C /

    < < 1

    > 1

    >= 1

    = = = 2

    != 2

  • :

    1() 0()

    a b a>b

    2 1 1

    2 3 0

    C

    && (and) || (or) ! (not). _1 . . _2

    :

    1() 0()

    a b a>b

    2 1 1

    2 3 0

    C

    && (and) || (or) ! (not). _1 . . _2

    ! .

  • O && 1 1(), 0() || 0 0(), 1() ! 0 1(), 0()

    .

    C

  • ( ) 1! 2

    * / % 3

    + - 4

    =, !=, = 5

    && 6

    || 7

  • a) 0.0

  • !(a = = b) a != b!(a ! = b) a = = b!(a < b) a >= b!(a b!(a > b) a = b) a < b

    !(..1 && ..2) (!..1) | | (!..2)!(..1 | | ..2) (!..1) && (!..2)

  • char xar1, xar2;

    xar1 = 0; xar2 = 6;

    xar1 xar2 xar < xar2

    0 6 1

    0 b 1(ACII) 0(EBCDIC) 4 - 0 4.

    + pezo - a

    pezo

  • getchar(); .

    char xar;

    xar = getchar(); /* */getchar(); /* \n */

    putchar(); .

  • ctype.h

    isdigit(c) c , 0.

    isalpha(c) c , 0.

    islower c , 0.

    isupper c , 0.

    isspace c (whitespace), 0.

  • ispunet(c) : c , 0.

    tolower(c) c , , c .

    toupper(c) c , , c .

  • - scanf

    scanf( , ); /

    short %hd

    int %d

    long %ld

    unsigned short %u

    unsigned %u

    unsigned long %lu

  • float %f %e

    double %lf %le

    long double %Lf %Le

    char %c

    int akeraios;

    scanf( %d, &akeraios); : 20

    _ _ _ _ _ 20

    20_ _ _ _

  • double syndelestis;

    scanf( %3lf, &syndelestis);

    1345.6 134.0

    3264.7e+1 326.0

    2.5e-3 2.5

    785694 785.0

    -567.8 -56.0

    5e+3 5.0

  • char xaraktiras;

    scanf(%c, &xaraktiras); int mikos; double platos; char xroma;

    scanf(%d%c%lf, &mikos, &xroma, &platos); / 50r1.3e3

    mikos=50, xroma=r, platos=1.3e3. 50 r 1.3e3

    mikos=50, xroma= , platos=0.000000

  • printf

    printf( , );

    int arithmos = 15;char apantisi = n;double riza =4.32;

    printf( x); xprintf(%d, arithmos); 15printf(%d, 25); 25printf(%c, apantisi); nprintf(%f, riza); 4.320000printf(%lf, riza); 4.320000

  • int arithmos = 15;char apantisi = n;double riza = 4.32;

    printf( x); xprintf(%d, arithmos); 15printf(%d, 25); 25printf(%d, arithmos+10); 25printf(%c, b); bprintf(%c, apantisi); nprintf(%f, riza); 4.320000printf(%lf, riza); 4.320000printf(%f, 2.25); 2.250000printf(%e, riza); 4.320000e+00

  • arithmos=15, printf(%5d, arithmos);

    1 2 3 4 5 1 5

    printf(%5d, arithmos); 1 2 3 4 51 5

    printf(%+5d, arithmos); 1 2 3 4 5 + 1 5

  • double arithmos = 65.4567

    printf(%10.4lf, arithmos); 1 2 3 4 5 6 7 8 9 10 6 5 . 4 5 6 7

    printf(%10.3lf, arithmos); 1 2 3 4 5 6 7 8 9 10 6 5 . 4 5 7

    printf(%10.3e, arithmos); 1 2 3 4 5 6 7 8 9 10 6 . 5 4 6 e + 0 1

  • platos = 10;dekadika = 4;

    printf(%*d, platos, arithmos);

    printf(%10d, arithmos); printf(%*.*f, platos, dekadika, arithmos);

    printf(%10.4f, arithmos);

  • C

    C .

  • 1. x1, x2, x3 .

    2. athroisma =x1 + x2 + x3

    3. mesi_timi = athroisma / 3.0 ;

    4. mesi_timi

  • \* *\

    #include

    int main (void){

    \* *\double x1, x2, x3, athroisma, mesi_timi;

    printf(\n :);scanf(%lf %lf %lf , &x1, &x2, &x3);printf(\n :);

  • printf(%5.3f %5.3f %5.3f , x1, x2, x3);\* *\

    athroisma = x1 + x2 + x3;

    \* *\

    mesi_timi = athroisma / 3.0;

    \*E *\

    printf(\n : %5.3f, mesi_timi);return 0;

    }

  • C

    x.

  • 1. x

    2. h

    3.

    4. x E

    2. h=sqrt(3)/2*x3. e=0.5*h

  • /* , */

    #include #include int main(void){

    /* */double x, h, e;printf(\n x :);scanf(%lf, &x);

  • /* */h = sqrt(3)/2.0 * x;/* */e = 0.5 * x * h;/* */printf(\nTo %f

    %f, h, e);return 0;

    }

  • : . :

    1. 2. 3.

    4. 5.

    Abu Jafar Mohammed ibn Musa al Khowarizmi (825 )

    Liber algorithmi

  • ()

    ( , )

  • ( )

    ( )

  • O :

    :

    n 1 :

    2 :

    n :

    .

    .

    .

  • .

  • E

    .

  • plithos

    sum = 0 k = 1, 2, ,plithos

    sum

    sum = sum + ar

    ar

  • plithos

    sum = 0 k=0

    k plithos

    sum

    sum = sum + ar

    ar

    k=k+1

  • o

    plithos

    sum = 0 k=0

    k

  • x, y z. .

    ( )

    1. x, y, z2. x > y

    63. y > z

    9

  • 4. z5. 106. x < z

    47. x8. 109. y10. .

  • x,y,z

    x > y

    y > z

  • x < z

    10

    x

    10

    y

    z

    .

    10

  • ( )

    1. x, y, z

    2. x > y x > z x

    y > x y > z

    y

    z

  • x,y,z

    x > y

    x > z

    x

    z

    y > x

    y > z

    y

    .

  • x, y, zx > y x > zNAI: xOXI: y > x y > z

    NAI: y: z

  • a, b c. () ,

    () () ,

    c

  • 1. a, b, c

    2. a=max{a,b,c}

    a

  • n 1 ( ).x + =

  • n

    i = 1(1)n

    , =0

    : , ,

    NAI : =0

    OXI : , , A

    O : x = -/ , , x

  • NSOLV_1GRD n

    i = 1(1)n

    , =0

    : , ,

    NAI : =0

    OXI : , , A

    O : x = -/ , , x

  • n , 1(1) .ia i n=

  • MAX(n, , MAX) n, , i = 1(1)n

    i=2(1)n

    MAX=l=1

    MAX <

    NAI : MAX = , l=i

    l, MAX

    1a

    ia

    ia

    ia

  • , 1(1) .ia i n=

    n

  • MIN_MAX(n, , MIN, MAX) n, , i = 1(1)n

    i=2(1)n

    NAI : MIN= , k=i

    MIN= , MAX=k=1 , l=1

    MIN >

    OXI : MAX <

    NAI : MAX = , l=i

    (k, MIN) , (l, MAX)

    1a 1a

    ia

    ia

    ia

    ia

    ia

  • MAX(n, , MAX) n, , i = 1(1)n

    i=2(1)n

    MAX=l=1

    MAX <

    NAI : MAX = , l=i

    l, MAX

    1a

    ia

    ia

    ia

  • MIN_MAX(n, a, MIN, MAX) n, , i = 1(1)n

    i=2(1)n

    NAI : MIN= , k=i

    MIN= , MAX=k=1 , l=1

    MIN >

    OXI : MAX <

    NAI : MAX = , l=i

    (k, MIN) , (l, MAX)

    1a 1a

    ia

    ia

    ia

    ia

  • 3

    . .

    , 1(1)ia i n=n

  • n, , i=1(1)n

    S = 0, P =1

    i= 1(1)n

    S=S +

    P = P *

    S, P

    ia

    ia

    ia

  • 4

    n

    ()

    Horner.

    1( ) .1 1 0n nP x a x a x a x an n

    = + + + + "

    ( )P

  • 1 2 1 0( ) ( (( ) ) )n n nP x a a a a a = + + + + +" " Horner

    n nb a=

    1na 2na 0a1a"na

    na+

    1nb

    1nb 2nb

    +""

    2b 1b

    1b+0b

    +

  • ( ) ( )( )P x Q x x = +

    1 2 1, , , , n n nb b b b " Q(x) :

    0 ( )b P = :

  • HORNER

    n, ,

    P =

    i= n-1(-1)0

    P = P * +

    , P

    , 1(1)a i n =na

    ia

  • a, b, c, n .

  • 2

    () (x, y) xOy (0,1,2, . . . , 8) .

    (. )

  • y2 6 1

    x57 0

    3 48

  • : .

    ( ) 2 .

    n ( 3)n

  • n

    i=2(1)n1it =

    s n=p s 2p =

    i=2p0it =

    i n>2p =

    i i p= +

    : 3p =OXI :

    2p p= +1pt =

  • i

    i=2(1)n

    0it :

  • n

    i=2(1)n1it =

    s n=p s 2p =

    i=2p0it =

    i n>2p =

    i i p= +

    : 3p =OXI :

    2p p= +1pt =

    while

    do while

    do while

    for

    if

    else

  • i

    i=2(1)n

    0it :

    for

  • 1. p=2 p=2. 4, 6, 8, ,

    2. p=3 p=3. 6, 9, 12, ,

    3. p . 2p, 3p, ,

    4. p 3

    5 .

    5. .

    kp n

    kp n

    kp nn

  • p

    ( p- p : )

    n2.p

    2p n

  • n i=2 n 1

    p=2

    s =

    p s

    1it =

    n

    {

  • {

    i=2p{

    t=0i=i+p_ i>n

    } p=2 p=3

    p=p+2_

    } i=2 n 1

    i

    p s

    0it

    1pt =

  • {

    i=2p{

    t=0i=i+p_ i>n

    } p=2 p=3

    p=p+2_

    } i=2 n 1

    i

    p s

    0it

    1pt =

  • {

    i=2p{

    t=0i=i+p_ i>n

    } p=2 p=3

    p=p+2_

    } i=2 n 1

    i

    p s

    0it

    1pt =

  • n i=2 n 1

    p=2

    s =

    p s

    1it =

    n

    {

    for(i=2; i

  • {

    i=2p{t=0

    i=i+p i

  • i=2 n 1

    i0it

    for(i=2; i

  • : n=10

    i=1 2 3 4 5 6 7 8 9 10

    111 11 11 1 1it

    p = 2 s = 10 3.16

    ;p s

  • p = 2 s = 10 3.16;p s

    2 10 NAIi=2*p=2*2=4

    4 0t = i=i+p=4+2=6i > n ;6 > 10 OXI

    6 0t = i=i+p=6+2=8i > n ;

    8 > 10 OXI

    8 0t = i=i+p=8+2=10

  • i > n ;

    10 > 10 OXI

    10 0t = i=i+p=10+2=1212 > 10

    p=2 ; p=3

    ;p s3 10

    i=2*3=6

    6 0t = i=i+p=6+3=9i > n ;

    9 > 10 OXI

    9 0t = i=i+p=9+3=12

  • i > n ;

    12 > 10

    p=2 ;

    3=2 ; OXI

    p=p+2=3+2+5

    1=1 ; 5 1 ;t =

    i=1 2 3 4 5 6 7 8 9 10

    it 1 1 10 0 0 0 01

  • 2i=2 2 0t 3i=3 3 0t

    4 0t i=4 55 0t i=5

    6 0t i=6 i=7 77 0t

    8 0t i=8 9 0t i=9

    10 0t i=10

  • : .

    ( ) () .

  • m, n

    m = nNAI : MKD = n , ( MKD )

    : Larger = mSmaller = n

    OXI : Larger = nSmaller = m

    O : n < m

    Remainder=Larger mod SmallerLarger = SmallerSmaller = Remainder

    Smaller = 0MKD = Larger ( MKD )

  • m, n

    m = nNAI : MKD = n , ( MKD )

    : Larger = mSmaller = n

    OXI : Larger = nSmaller = m

    O : n < m m n12 1612 40 4

    MKDRemainder=Larger mod SmallerLarger = SmallerSmaller = Remainder

    Smaller = 0MKD = Larger ( MKD )

  • (Binary Search)

    n :

    A :

    x k x , x.

    0 1 2 1na a a a "

    0a 1a 2a 1na 3a 2na

    0 1 2 3 4 " n-2 n-1a :

    i :

  • : n=10 , x=105

    200105989263472824165

    9876543210a :i :

    low mid=(0+9)/2=4 high

    1

    x > a[mid]105 > a[4]=47low = mid + 1= 4+1=5

  • 200105989263472824165

    9876543210

    low highmid

    i :a :

    2 x > a[mid]105 > a[7]=98low = mid + 1= 7+1=8

  • 200105989263472824165

    9876543210

    3

    a :i :

    low high

    mid

    x = a[mid]105 = a[8]=105

    a[8]=105

  • n, ia , i=0(1)n-1 xlow=0 high=n-1low high

    mid = (low+high)/2x < a[mid] : high = mid -1OXI : x > a[mid]

    : low=mid+1OXI : mid

    ( = , x)

  • if

    if ( )

  • ()

    0()

    if

  • H

    x>0 y = y - x

    C

    if ( x>0 )y = y - x;

    if (b * b 4 * a * c >= 0)

    d = sqrt(b * b 4 * a * c);

    acbacb 4d,04 22 =

  • C x y.

    prosorini

    x y

    1 3

    2

  • #include int main(void){

    /* */double x, y, prosorini;/* */printf(\n x y:);scanf(%lf %lf , &x, &y);printf(\nx = %f y = %f \n, x, y);

  • if (x < y){

    prosorini = x;x = y;y = prosorini;

    }printf(\n = %f \t = %f, x, y);return 0;

    }

  • if-else

    if ( )_1

    else

    _2

  • _1 _2

    0() ()

  • C

    x < y, min=x, if (x < y) min=y min = x;

    elsemin = y;

    x 0, sum1 = sum1 + x if (x >= 0) sum2 = sum2 + 1 {

    sum1 = sum1 x sum1 = sum1 + x; sum2 = sum2 1 sum2 = sum2 + 1;

    } else {sum1 = sum1 x;sum2 = sum2 1;

    }

  • if

    (i) if ( _1 )if ( _2 )

    _1

    else

    _2

  • (ii) if ( _1 )if (_2)

    _1

    else

    if ( _3)_2

    else

    _3

  • , , , .

  • #include /*#include */int main(void){

    char c;printf(\n :);c = getchar(); /* */if (c == )

    printf(\n );else

  • if (0
  • switch

    switch (){

    case _1 :

    _1

    break;

    case _2:

    _2

    break;

    ...

    default :

    }

  • 1 7. C , .

  • /* */

    #include int main(void){

    /* */int arithmos;

    printf( 1 7:);scanf(%d, &arithmos);

  • switch (arithmos){

    case 1:printf();break;

    case 2:printf();break;

    case 3:printf();break;

  • case 4:printf();break;

    case 5:printf();break;

    case 6:printf();break;

  • case 7:printf();break;

    default:printf(

    1 7);}return 0;

    }

  • . (a) 1 , (b) 6, (c) , (d) 10 . C .

  • /* */#include int main(void){

    /* */char apantisi;int vathmos = 0;printf( = ? (a, b, c, d));scanf(%c, &apantisi);getchar(); /* CR*/

  • printf( apantisi=%c , apantisi);switch (apantisi){

    case a:

    vathmos++;break;

    case b:vathmos +=6;break;

    case c:

    break;

  • case d:vathmos +=10;break;

    default:printf( );break;

    }printf( = %d, vathmos);return 0;

    }

  • C . :

  • #include #define XILIARIKO 1000#define PENTAKOSARIKO 500#define KATOSTARIKO 100#define PENHNTARIKO 50#define EIKOSARIKO 20#define DEKARIKO 10#define TALLHRO 5#define DIFRAGO 2#define DRAXMH 1

  • int main(void){

    /* */double timi, poson;int resta, plithos;printf(

    );scanf(%f %f, &timi, &poson);resta = poson - timi;

  • if (resta < 0)printf( );

    elseprintf( \n);if (resta >= XILIARIKO){

    plithos = resta/XILIARIKO;resta = resta % (plithos * XILIARIKO);printf(%d , plithos);

  • if (plithos > 1)printf(a\n);

    elseprintf(o\n);

    }if (resta >= PENTAKOSARIKO){

    plithos = resta/PENTAKOSARIKO;resta% = plithos * PENTAKOSARIKO;printf(%d , plithos);

  • if (plithos > 1)printf(a\n);

    elseprintf(o\n);

    }if (resta >= KATOSTARIKO)

    ...

    return 0;}

  • for (_1; _2; _3)

    _1 =

    _2 =

    _3 =

  • _2

    _3

    ()

    0 ()

    for

    _1

  • >

    for ( i = 1; i

  • : , n.

    1

    n

    kk

    =

  • /* 1+2++n*/#includeint main(void){

    /* */int i, n, athroisma;

    printf( n = );scanf(%d, &n);

  • /* */athroisma = 0; /* */for (i = 1; i
  • for (i = 1; i
  • for :for (i = n; i >= 1; i)

    athroisma += i;

    athroisma i1 i = 3; 0 32 3 >= 1 (i >= 1) 0 33 athroisma += 3; 3 34 i = 2; 3 25 2 = 1) 3 26 athroisma += 2; 5 27 i = 1; 5 18 1 = 1) 5 19 athroisma += 1; 6 110 i = 0; 6 111 0 >= 1 (i >= 1) 6 1

    for

  • , , . .

  • /* */#include int main(void){

    /* */double epitokio, kefalaio, tokos, axia_kef;int etos, plithos_eton;

    printf( , , \n);

  • scanf(%f %f %f,&kefalaio, &plithos_eton, &epitokio);

    axia_kef = kefalaio;printf( \n);for (etos = 1; etos

  • , .

  • /* */#include int main(void){

    /* */int arithmos =-1, plithos = 0, athroisma = 0;double mesi_timi;

    printf( . 0 );

  • for ( scanf(%d, &arithmos); arithmos != 0;scanf(%d, &arithmos ))

    {athroisma += arithmos;plithos ++;printf( . 0

    );}

  • if (plithos == 0)mesi_timi = 0.0;

    elsemesi_timi = (double) athroisma / plithos;

    printf( : %6.2f, mesi_timi);return 0;

    }

  • for .

    for ( ; ; ) /* */{

    scanf(%d, &arithmos);if (arithmos == 0)

    break; /* for */athroisma += arithmos;plithos ++;printf( . 0

    );}

  • while

    while ( )

  • ()

    0 ()

    whilewhile ( )

  • .

    n! = 1 2 3 n, 0! = 1.

    par = 1;metritis = 2;while (metritis

  • . 0.

    int arithmos, athroisma = 0;printf( .);printf(\n .);scanf(%d, &arithmos);while (arithmos){

    athroisma += (arithmos * arithmos);printf( .);printf(\n .);scanf(%d, &arithmos);

    }

  • while,

    .

    while (xar = getchar() ) = = ); /* */

    , .

  • #include int main(void){

    float ginomeno = 1.0, arithmos;char xar = n;while (xar ==n){

    printf(\n : \n);scanf(%f, &arithmos);ginomeno *= arithmos;

  • getchar(); /* */printf(\n n()

    o(xi) :);xar = getchar(); /* */

    }/* while */printf( = %f, ginomeno);return 0;

    }

  • :

    1 + 1/2 + 1/3 + 1/4 +

    = 0.5 10-2.

  • #include const float EPSILON = 0.5e 0.2;int main(void){

    /* */float athroisma = 0.0, oros = 1;int plithos;plithos = 1;

  • while ( oros >= EPSILON){

    athroisma += oros;plithos ++;oros = 1.0 / plithos;

    }printf( = %d. =

    %6.3f, plithos-1, athroisma);return 0;

    }

  • for (_1; _2; _3)

    _1;

    while ( _2 ){

    _3;

    }

  • do - while

    do - while

    do

    while ( ) ;

  • ()

    0 ()

    do - while

    do

    while ( )

  • , :

    do{

    printf(\n\n :);scanf(%d, &arithmos);

    } while (arithmos

  • C .

  • /* */#include int main(void){

    double arithmos, athroisma = 0.0, mesi_timi;int metritis = 0;

    printf( );printf( 1 \n);scanf(%d, &arithmos);

  • if (arithmos ==-1)printf( \n);

    else{

    do{

    athroisma += arithmos;metritis ++;printf(

    :);

  • printf( 1 :);

    scanf(%f, &arithmos);} while (arithmos != -1.0);

    mesi_timi = athroisma / metritis;printf( = %8.2f \n, mesi_timi);printf( = %d \n, metritis);

    return 0;}

  • , k do while :

    y = 0;k = 0;do{

    y++;printf(y = %d\n, y);

    }while (k != 10);

  • C (string) , ( ).

  • #include #define APOSTROFOS \int main(void){

    /* */int plithos_xar = 0;char xaraktiras;printf( \n);

  • do /* */scanf(%c, &xaraktiras);

    while (xaraktiras != APOSTROFOS);printf(

    : %c, APOSTROFOS);scanf(%c, &xaraktiras);while (xaraktiras != APOSTROFOS){

    printf(%c, xaraktiras);plithos_xar++;scanf(%c, &xaraktiras);

    }

  • printf(%c \n, APOSTROFOS);printf( = %d \n, plithos_xar);return 0;

    }

  • for (i = 1; i

  • for (athroisma = 0, i = 1; i

  • EOF

    Carriage Return, \n.

    Ctrl-Z (DOS), EOF.

  • ( ) . . .

  • /* */#include #define PLITHOS 2 /* */int main(void){

    char xar;int metritis;

    printf( %d \n,PLITHOS);

  • for (metritis=1; metritis
  • C .

  • #include int main(void){

    nt xar;

    printf( \n);printf( Ctrl-Z \n);xar = getchar();

  • while (xar != EOF){

    while (xar != \n){

    putchar(xar);xar = getchar();

    }putchar(\n);xar = getchar();

    } return 0;}

  • (Functions)

    ( ){

    _1

    _2

    :

    _

    }

  • _1 _1,

    _2 _2,

    _3 _3,

    :

    :

    _ _

    int a, double x, float y, char xar

  • void ektyposi_epilogon(void){

    printf( 1 1\n);printf( 2 2\n);printf( 3 3\n);

    }

  • - ( );

    ektyposi_epilogon (); () - ( ) ;

    void ektyposi_epilogon( void ) ;

    void ektyposi_epilogon(); /* */

  • ektyposi_epilogon.

    #include void ektyposi_epilogon (void); /* */int main(void){

    ektyposi_epilogon(); /**/return 0;

    }

  • /* */void ektyposi_epilogon(void){

    printf( 1 1 \n);printf( 2 2 \n);printf( 3 3 \n);

    }

  • return

    return ( ) ; (=void) return

    ()

    return;

  • ektyposi_epilogon. .

  • #include /* */void ektyposi_epilogon (void);int epilogi_xristi(void);int main(void){

    /* */int epilogi;char synexisete = n; /* n(ai) *//* */

  • while (synexisete == n){

    epilogi = epilogi_xristi();printf( ; (n/o):);scanf(%c, &synexisete);getchar(); /* CR */

    }return 0;

    }/*: .: . : epilogi*/

  • int epilogi_xristi(void){

    /* */char sosti_epilogi = ;/* oxi */int epilogi;

    /* */while (sosti_epilogi == ){

    ektyposi_epilogon();scanf(%d, &epilogi);

  • if (epilogi ==1 || epilogi == 2 || epilogi ==3)sosti_epilogi = n;

    }/* epilogi */

    return epilogi;}

  • /* */void ektyposi_epilogon(void){

    printf( 1 1 \n);printf( 2 2 \n);printf( 3 3 \n);

    }

  • (value) (pointers)

  • , :

    int megistos (int x, int y, int z); /**/

    int megistos( int, int, int ); /* */

    .

  • /* : . : .:

    */char prosimo (float arithmos){

    if (arithmos < 0)return -;

    elsereturn +;

    }

    /* */

  • /*: .: .: */

  • int megistos (int ar1, int ar2, int ar3){

    int meg; /* */if (ar1 > ar2)

    meg = ar1;else

    meg = ar2; /*meg = max ( meg1, meg2) */if (ar3 > meg)

    meg = ar3;return (meg);

    }

  • megistos

    pros1=max(num1, num2, num3)pros2=max(num4, num5, pros1)

  • #include /* */int megistos (int ar1, int ar2, int ar3);int main(void){

    int num1, num2, num3, num4, num5;int pros1, pros2;printf( 5 :);scanf(%d %d %d %d %d ,

    &num1, &num2, &num3, &num4, &num5);

  • pros1 = megistos (num1, num2, num3);pros2 = megistos (num4, num5, pros1);

    printf( : %d, pros2);return 0;

    }/*:

    .: .:

    */

  • int megistos (int ar1, int ar2, int ar3){

    int meg;if (ar1 > ar2)

    meg = ar1;else

    meg = ar2;if (ar3 > meg)

    meg = ar3;return (meg);

    }

  • n- Fibonacci.

    Fibonacci

    0 1 1 2 3 5 8 13 . . .

  • #include /* */int fibonacci (int n);int main(void){

    int n, fib;printf( :);scanf(%d, &n);fib = fibonacci(n);printf( %d - : %d, n, fib);

  • return 0;}/*: n- fibonacci.: .: fibonacci.*/int fibonacci (int n){

    int protos = 0, deyteros = 1, metritis = 3, arithmos;if (n == 1)

    arithmos = protos;else

  • if (n == 2)arithmos = deyteros;

    while (metritis

  • :

    2 3x x x1- + - +1! 2! 3!

    x.

    , =0.510-6.

  • float series (float x, float epsilon){

    float oros = 1.0, athroisma = 1.0;int n = 1;while (abs(oros) > epsilon){

    oros *= -x/n;athroisma += oros;++n;

    }return (athroisma);

    }

  • series, :

    (x, ). x .

    2 3x x x1- + - +1! 2! 3!

  • #include #include float series(float x, float epsilon);int main(void){

    float x1, eps, timi;char apantisi = n, nea_grammi;while (apantisi == n){

    printf( x :);

  • scanf(%f %f, &x1, &eps);timi = series (x1, eps);printf(\n %7.3f %e %7.3f , x1, eps, timi);printf( ; (n/o):);scanf(%c, &apantisi);getchar(); /* CR */

    }return 0;

    }

  • , n.

    int athroisma_tetr (int n){

    int i, athroisma= 0;for (i=1; i

  • /* : */

    #include #define N 5int main(void){

    int n;for (n=1; n

  • , n k.

    nk

    i=1i

  • , mn m n.int dynami (int m, n){

    int i, ginomeno = 1;for (i=1; i

  • int athroisma_dyn (int k, n){

    int i, athroisma = 0;for (i=1; i

  • auto, register, static, extern

    void ypologismos (void){

    static int fores = 0;.

    .

    .

    fores++;printf( %d ,

    fores);}

  • #include int b, c, d; /* */void e(float f, g, h);int main(void){

    /* */return 0;

    }void e(float f, g, h) /* f, g, h, i, j */{

    int i,j;/* */

    }

  • #include int d; /* */void sygxisi (int a, int b);int main(void){

    int a, b, c; /* main*/a = 1;b = 2;c = 3;d = 4; /* ! */

  • printf(\n%8d %8d %8d %8d, a, b, c ,d);sygxisi (a, b);printf(\n%8d %8d %8d %8d, a, b, c, d);

    }void sygxisi (int a, int b){

    float c; /* */a = 5; b = 6;c = 7.3; d = 8;printf(\n%8d %8d %8.1f %8d, a, b, c, d);

    }

  • 1 2 3 4

    5 6 7.3 8

    1 2 3 8

  • (pointers)

    int *arith_dktis;char *xarakt_dktis;

    int x = 10, *p, *q;p = 0;p = NULL;p = &x;q = p;

    p

    q

    x

    10

  • double x = 3.1, y, *p;p = &x;

    y = *p;

    y = *&x;

    y = x;

    p

    x

    *p

    3.1

  • (pointers)int *p, *q, x, y;p=&x;q=&y;

    p

    q

    x

    y

  • 5p

    8q

    p=q;

    8p

    8q

    5p

    8q

    *p=5;*q=8;

  • 5p

    8q

    *p=*q;

    8p

    8q

    5p

    8q

    *p=5;*q=8;

  • (call by value) (call by reference)

  • void g(int k);int main(void){

    int a;a=1;g(a);printf(a=%d\n, a);return 0;

    }

    void g( int k){

    k++;}

    1

    1 2

    a k

    a

    k++

    1 1

    KATAa k

    1

    a

  • void g(int *k);int main(void){

    int a;a=1;g( &a);printf(a=%d\n, a);return 0;

    }

    void g( int *k){

    *k++;}

    1

    2

    a

    k

    k

    a

    &a

    &a

  • ,

    max(a, b) a b.

    /* */void megisti (int a, int b, int *meg){

    if (a > b)*meg = a;

    else*meg = b;

    } megisti(x, y, &z);

  • float afksisi (float x);int main (void ){

    float x1, y;x1 = 1;y = afksisi (x1);

    printf (%f, y);return 0;

    }float afksisi (float x){

    x = x+1;return (x);

    }

    x1 1 x1=1;

    x 1 /

    x 2 x= x+1;

    afksisi x1 1 / main

    H ( )

  • x1 1 x1=1;

    x 1 /

    x 2 x= x+1;

    afksisi x1 1 / main

    H ( )

  • void afksisi (float *x);int main ( ){

    float x1;x1 = 1;afksisi (&x1);

    printf (%f,x1);return 0;

    }void afksisi (float *x){

    *x = *x+1;}

    x1 1 x1=1;

    *x (x1) 1 *x 2 *x=*x+1;

    afksisi x1 2 main

    .

  • x1 1 x1=1;

    *x (x1) 1 *x 2 *x=*x+1;

    afksisi x1 2 main

    .

  • H .

    .

  • #include int d; /* */void sygxisi(int a, int b);int main (void ){

    int a,b,c;a = 1; b = 2;c = 3; d = 4;printf (\n%8d %8d %8d %8d,a,b,c,d);sygxisi (a,b);printf (%8d %8d %8d %8d,a,b,c,d);return 0;

    }

  • void sygxisi(int a, int b){

    float c; /* */a = 5;b = 6;c = 7.3;d = 8;printf (%8d %8d %8.1f %8d,a,b,c,d);

    }

    1 2 3 45 6 7.3 81 2 3 8

  • #include int d; /* */void sygxisi(int *a, int *b);int main (void)

    {int a,b,c;a = 1; b = 2;c = 3; d = 4;printf (\n%8d %8d %8d %8d,a,b,c,d);sygxisi(&a, &b);printf (%8d %8d %8d %8d,a,b,c,d);return 0;

    }

  • void sygxisi (int *a, int *b){

    float c; /* */*a = 5;*b = 6;c = 7.3;d = 8;printf (%8d %8d %8.1f %8d,*a,*b,c,d);

    }

    1 2 3 45 6 7.3 85 6 3 8

  • .

    void enalagi (int *proti, int *deyteri)/* */{

    int prosorini;prosorini = *proti;*proti = *deyteri;*deyteri = prosorini;

    }

  • , .

    #include void enalagi (int *proti, int *deyteri);int main (void){

    int proti_1, deyteri_1;printf(\n:);

  • scanf (%d, &proti_1);printf (\n:);scanf (%d, &deyteri_1);enalagi (&proti_1, &deyteri_1);printf (\n = %d, = %d,

    proti_1, deyteri_1);return 0;

    }

    C N Fibonacci. Fibonacci. .

  • #include void fibonacci (int *palios, int *neos);int main (void){

    int N, i, trexonfib, epomenosfib;printf ( N:);scanf (%d, &N);printf (\n %d fibonacci

    :\n\n, N)trexonfib = 0;

  • epomenosfib = 1;for (i = 1; i
  • default:break;

    }}return 0;

    }void fibonacci (int *palios, int *neos){

    int prosorinos;prosorinos = *palios + *neos;*palios = *neos;*neos = prosorinos;

    }

  • , (recursive function)

    .

  • n! = n(n-1)!, 0! = 1

    n = = 0 1 ( ) n 1, : n * factorial (n-1) ( )int factorial (int n){

    if (n = = 0) /* */return 1;

    elsereturn (n * factorial (n-1)); /* */

    }

  • factorial(3);

    0 factorial(3)6

    1 3 * factorial(2)2

    2 2 * factorial(1)1

    3 1 * factorial(0)

    1

  • ( , , ...).

  • /* */#include void antistrofi (long *akeraios);int main (void){

    long arithmos;printf (\n );scanf (%d, &arithmos);printf(\n :);antistrofi (&arithmos);return 0;

    }

  • void antistrofi (long *akeraios){

    do{

    printf (%d, *akeraios % 10);*akeraios = *akeraios / 10;

    }while (*akeraios != 0);

    }

  • #include void antistrofi (long akeraios);int main (void){

    long arithmos;printf ( );scanf (%d, &arithmos);printf(\n :);antistrofi (arithmos);return 0;

    }

  • void antistrofi (long akeraios){

    printf (%d, akeraios % 10);/* */akeraios = akeraios / 10;if (akeraios != 0)

    antistrofi (akeraios);}

  • .#include void stoivaxeharaktires (void );int main (void ){

    printf (\n : );stoivaxeharaktires ( );printf (\n\n);return 0;

    }

  • void stoivaxeharaktires (void ){

    char xar;scanf (%c, &xar);if (xar != \n)

    stoivaxeharaktires ( );printf (%c, xar);

    }

  • 1 scanf (%c, &xar); 2 scanf (%c, &xar); h3 scanf (%c, &xar); e

    3 printf (%c, &xar); o e2 printf (%c, &xar); o h1 printf (%c, &xar); o T

  • m n. m n (m n)

    athroisma (m,n) = m + (m + 1) + + n

  • int athroisma (int m, n){

    if (n == m)return n;

    elsereturn (n + athroisma (m, n-1));

    }

  • /

    0 athroisma (1,5)1+2+3+4+5

    1 5+athroisma (1,4)1+2+3+4

    2 4+athroisma (1,3)1+2+3

    3 3+athroisma (1,2)1+2

    4 2+athroisma (1,1)1

    5 athroisma (1,1)

  • Fibonacciint Fibonacci (int n){

    if (n

  • F5

    F5

    F4 F3

    F3 F2 F2 F1

    F2 F1 F1 F0 F1 F0

    F1 F0

  • :

    :

    double f (int k){

    /* f ()*/}

    =

    n

    mkkf )(

  • double athroisma (int m, int n){

    int k;double athr = 0.0;for (k = m; k

  • , athroisma :

    double athroisma (double (*f) (), int m, int n){

    int k;double athr = 0.0;for (k = m; k

  • /* 10 */#include

    /* */double f1 (int k1);double f2 (int k2);double athroisma (double (*f) (), int m, int n);

    main (){

    printf(\n%.5f %.5f\n\n,athroisma(f1, 1, 10), athroisma(f2, 1, 10));

    }

  • double f1 (int k1){

    return (k1);}

    double f2 (int k2){

    return (k2 * k2);}

  • ENUMERATION

    :enum sxoles {thetikonepist, philosophiki, iatriki,

    theologiki, nomiki, odontiatriki};enum tmimata {pliroforikis, mathimatiko, physiko,

    ximiko, geologiko, pharmakeytiko, biologiko} :enum sxoles s_athinon, s_thessalonikis, s_ioanninon;enum tmimata t_athinon, t_thessalonikis, s_ioanninon;

  • :s_athinon = iatriki;s_ioanninon = philosophiki;t_athinon = pliroforikis;

    :s_athinon = pliroforiki ( )

    :if (s_athinon = = iatriki)

    printf ( );pliroforiki < mathimatiko ximiko ! = physiko

  • :

    enum {peyko, elia} dentro;

    . :

    enum {deytera = 2, triti, tetarti, pempti = 7, paraskevi,savato, kyriaki} imeres;

  • enum stock {fakeloi, xarti, molyvia, stylo}enum stock temaxio; /* */:

    switch (temaxio) {case fakeloi: printf (\n);

    break;case xarti: printf (\n);

    break;case molyvia: printf(\n);

    break;case stylo: printf(\n);

    break;}

  • . , . . 350 ./.

    .

  • /* */

    #include

    #define EPIDOMA 350 /* 350 ./*/

    enum imera {deytera, triti, tetarti, pempti, paraskevi, savato, kyriaki};int main (void){

    enum imera ergasimi;

    double oromisthio, misthos, ores, epidomata;

  • int ores_ergasias;

    printf (\n : );scanf (%1f, &oromisthio);misthos = 0.0;

    epidomata = 0.0;

    /*

    */

  • for (ergasimi = deytera; ergasimi
  • case tetarti:

    case pempti:

    case paraskevi:

    ores = ores_ergasias;

    break;

    case savato:

    ores = 1.5 * ores_ergasias;

    break;

  • case kyriaki:

    ores = 1.0 * ores_ergasias;

    break;

    default:

    printf ( ergasimi);

    break;

    }/* switch */

  • epidomata+=ores_ergasias * EPIDOMA;

    misthos += ores * oromisthio;

    }/* for */misthos += epidomata;

    printf (O : %f,misthos);

    return 0;

    }

  • (bubble sort) (selection) (quicksort) (merge sort)

  • (sequential search) (binary

    search)

  • 0 1 2 3 4 5 . . . 18 19

    ? ? ? ? ? ? ? ? ? ? ? ?

    _ [ ] ;

    #define N 20

    double a[N]; a[4] 5 i = 3 a[i+2] 6

  • for ( i=0; i
  • athroisma = 0;

    for ( i=0; i

  • .

    .

    double mesos_oros ( int vathmos[], int megethos);{

    int i; double athroisma = 0.0;

    for ( i=0; i< megethos; i++)athroisma += vathmos[i];

    return ( athroisma / megethos ); }

  • .

  • /* */

    #include #define PLITHOS 26int main (void){

    double pinakas[PLITHOS];int xar;int i, grammata;

  • /* */for (i = 0; i < PLITHOS; ++i)

    pinakas [i] = 0.0;grammata = 0;printf (\n . Enter Cltrl-Z

    );while (xar = getchar() != EOF){

    if (A

  • case A:pinakas [0]++; break;

    case B:pinakas [1]++; break;

    :

    :

    case Z:pinakas [25]++; break;

    default : printf( );}

    }

  • for (i = 0; i < PLITHOS; i++)pinakas[i] /= grammata;

    printf (\n : \n);i=0;for (xar=A; xar

  • :

    .

  • int *dktis;

    dktis = malloc(sizeof(int));

    *dktis = 10;

    free(dktis);

    dktis = NULL;

    ?

    NULL

    ?

    10

    dktis

    dktis

    dktis

    dktis

    dktis

    *dktis

    *dktis

  • int *a;

    a = malloc(megethos * sizeof(int));a

    ? ? ? ? ? ? ? ?

    a[0] a[1] a[2] .a[megethos-1]

    free( a );a = NULL;

  • (bubble sort) function .

    , 1(1)i i n =

    1

    2

    3

    4

    m[0] 60 42 42 42 42 25 25m[1] 42

    60

    60

    60 25 42 42m[2] 83 83 25 25

    60

    60

    60m[3] 25 25 83 75 75 75 75m[4] 75 75 75 83 83 83 83

  • void fysalida (int m[], int n)/* n m[] */

    {int i, j;for (i = n-1; i>0; ++i)

    for ( j =0; j< i; ++j)if (m[j] > m[j+1])

    andallagi(&m[j], &m[j+1]);}

    ( )2O n

  • void andallagi(int *p, int *q){

    int pros;

    pros = *p;

    *p = *q;

    *q = pros;}

  • void fysalida(int m[], int n){ int pros, i; char taxinomisi= o; /* */

    do { taxinomisi = n;for (i=0; i m[i+1])andallagi( &m[i], &m[i+1]);taxinomisi = o;

    n = n - 1; /* */

    } while (taxinomisi == o); }

  • #include

    #define N 200

    void andallagi(int *p, *int *q);void fysalida(int m[], int n)int main(void){

    int i, pinakas[N];printf(\n %d , N);for (i=0; i

  • printf(\n :);for (i=0; i
  • (selection sort)

    function (selection sort).

    1 2 3 4m[0] 60 83 83 83 83m[1] 42

    42 75 75 45m[2] 83 60

    60

    60

    60m[3] 25 25 25 25 42m[4] 75 75 42 42 25

    , 1(1)i i n =

  • void epilogi(int m[], int n) /* n m[] */{

    int i, j, meg;for ( i=0; i

  • void andallagi(int *p, int*q){

    int pros;

    pros = *p;

    *p = *q;

    *q = pros;}

  • #include

    #define N 200

    void andallagi(int *p, *int *q);void epilogi(int m[], int n);int main(void){

    int i, pinakas[N];printf(\n %d , N);for (i=0; i

  • printf(\n :);for (i=0; i
  • (quicksort) = (4)

    4 3 1 9 2 6 5 p q

    4 3 1 9 2 6 5 p q

    4 3 1 9 2 6 5 p q

  • 4 3 1 9 2 6 5 p q

    4 3 1 9 2 6 5 p q

    4 3 1 9 2 6 5 p q

    4 3 1 2 9 6 5 ()p q

  • 4 3 1 2 9 6 5pq

    [2 3 1] 4 [9 6 5]

    [2 3 1] 4 [9 6 5][1] 2 [3] 4 [5 6] 91 2 3 4 5 [6] 91 2 3 4 5 6 9

  • void grigori_tax (int a[ ], int arxi, int telos)/* H a[ ] */{

    int p, q, odigo;if (arxi < telos )/* (arxi >= telos) ( ) */{

    p = arxi;q = telos;odigo = a[arxi];

  • /* p>= q */while (p < q){

    /* q */while ( a[q] > odigo )

    --q;/* p */while ( a[p ]

  • /* p = q, p q */

    andallagi (&a[arxi], &a[q]);grigori_tax (a, arxi, q-1);grigori_tax (a, q+1, telos);

    }}

    O(nlogn)

  • #include

    #define N_1 200

    void andallagi(int *p, *int *q);void grigori_tax(int m[], int arxi, int telos);int main(void){

    int i, N, pinakas[N_1];printf(\n :);scanf(%d, N);printf(\n %d , N);

  • for (i=0; i
  • taxi.hvoid fysalida(int m[], int n);void andallagi (int *p, int *q);void epilogi(int m[], int n);void grigori_tax(int a[], int arxi, int telos); taxi.c

    #include "taxi.h"

    taxi.h

    #include

    #include taxi.c

    int main(void)

  • () .

    i

    a

    b kj

    c

  • a[i] b[j] c[k].

    if a[i] < b[j]{

    c[k] = a[i];++ i;++ k;

    }else /* b[j]

  • a[ ], b[ ] c[ ].

    a

    b

    c

    b[ ], a[ ] c[ ].

  • void syghonefsi (int a[ ], int b[ ], int c[ ], int n, int m)

    /* a[i] b[j] c[k] */

    {int i, j, k;i = 0; /* a[ ] */j = 0; /* b[ ] */k = 0; /* c[ ] */

    /* a[i] b[j] c[k] */

  • while (i < n && j < m)if (a[i] < b[j]){

    c[k] = a[i];++ i;++ k;

    }else{

    c[k] = b[j];++ j;++ k;

    }

  • /* a[ ], b[ ] c[ ] */

    while (j < m){

    c[k] = b[j];++ j;++ k;

    }

  • /* b[ ], a[ ] c[ ] */

    while (i < n){

    c[k] = a[i];++ i;++ k;

    }

  • #include

    #define N1 200

    int main(void){

    int i, N, M, pin1[N1], pin2[N1], neos_pin[N1];printf(\n 1 );

    scanf(%d, &N);printf(\n 1 );for (i=0; i

  • printf(\n 2 );scanf(%d, &M);printf(\n 2 );for (i=0; i
  • printf(\n :);for (i=0; i< N+M; ++i)

    printf(\n%d, neos_pin[i]);return 0;

    }

  • .

  • /* */

    void seiriaki_anazitisi_1 (int kleidi, int megethos, int pinakas [ ],int *deiktis, int *vrethike)

    {int i;*vrethike = 0; /* */*deiktis = -1;

  • for (i = 0; i < megethos; i++)if (kleidi = = pinakas [i]){

    deiktis = i;*vrethike = 1; /* */break;

    }}

  • /* () */

    void seiriaki_anazitisi_2 (int kleidi, int megethos, int pinakas [ ],int *deiktis, int *vrethike)

    {int i;*vrethike = 0; /* */*deiktis = -1;

  • for (i = 0; i < megethos; i++)if (kleidi < pinakas [i]) /* */

    break;else

    if (kleidi = = pinakas [i]){

    *deiktis = i;*vrethike = 1;break;

    }}

  • (Binary Search) 18

    2 3 5 7 8 [11 15 17 18 19]

    11 15 17 [18 19]

    18 19

    0 1 2 3 4 5 6 7 8 9

  • /* .*/

    void dyadiki_anazitisi_1 (int kleidi, int pinakas [ ], int megethos,int *deiktis, int *vrethike)

    {int arxi, telos, mesaio;*vrethike = 0;arxi = 0;telos = megethos-1;while ( arxi

  • {mesaio = (arxi + telos) / 2;if (kleidi = = pinakas [mesaio]){

    *deiktis = mesaio;*vrethike = 1; /* */

    }else /* */

    if (kleidi < pinakas [mesaio])telos = mesaio-1;

    else /* kleidi >= pinakas[mesaio] */arxi = mesaio+1;

    }}

  • A /* */

    void dyadiki_anazitisi_2 (int kleidi, int pinakas [ ], int arxi,int telos, int *deiktis, int *vrethike)

    {int mesaio;*vrethike = 0;if (arxi

  • if (kleidi = = pinakas [mesaio]){

    *deiktis = mesaio;*vrethike = 1;

    }else

    if (kleidi < pinakas [mesaio])dyadiki_anazitisi_2 (kleidi, pinakas, arxi, mesaio-1,

    deiktis, vrethike);else

    dyadiki_anazitisi_2 (kleidi, pinakas, mesaio+1,telos, deiktis, vrethike);

    } }

  • typedef

    typedef - ;

    typedef int typos_stoixeiou;

    typos_stoixeiou dianysma[N]; int double,

    typedef double typos_stoixeiou ;

    1

    #define N 100

    typedef int typos_stoixeiou;

    typedef typos_stoixeiou dianysma[N];

    typedef typos_stoixeiou dianysma[N][N];

  • dianysma v1, v2, v3 ;

    pinakas a, b, c ;

    :

    2

    int v1[N], v2[N], v3[N] ;int a[N][N], b[N][N], c[N][N] ;

    3 ( )#define n 100

    typedef int typos_stoixeiou ;

    typedef typos_stoixeiou dianysma[N];typedef dianysma dianysma[N];

  • struct -

    {_1 -_1;

    _2 -_2;

    _3 -_3;

    ..

    _ -_;

    }

  • struct foititis

    {char onoma[30];int AM;

    int v_askiseon;

    int v_graptou;

    int v_telikos;

    }

  • struct foititis karas, alexiou;

    struct onoma_ypal

    {char eponymo[20];char onoma[20];

    }

  • struct ypallilos

    {int ar_mitroou;

    struct onoma_ypal on_yp;

    int ilikia;

    float misthos;

    }

  • struct foititis

    {char onoma[30];int AM;

    int v_askiseon;

    int v_graptou;

    int v_telikos;

    } karas, alexiou;

  • struct /* */

    {char onoma[30];int AM;

    int v_akiseon;

    int v_graptou;

    int v_telikos;

    } karas, alexiou;

  • typedef struct

    {char onoma[30];int AM;

    int v_askiseon;

    int v_graptou;

    int v_telikos;

    } foititis;foititis karas, alexiou;

  • karas . onoma = Karas;

    karas . AM = 1234;

    karas . v_askiseon = 75;

    foititis karas, alexiou;

    .

    karas = alexiou;

    , foititis

  • /* foititis */

    foititis eisagogi_dedomenon (void){

    foititis foit;

    printf ( :);gets (foit.onoma);printf ( :);

  • scanf (%d, &foit.AM);printf ( :);scanf (%d, &foit.v_askiseon);printf ( :);scanf (%d, &foit.v_graptou);printf ( :);scanf (%d, &foit.v_telikos);

    return foit;}

    foit_1 = eisagogi_dedomenon(); /**/

  • foititis *foit;

    foit -> AM (*foit). AMfoit -> onoma

    foit -> v_graptou

    foit -> v_akiseon

  • void eisagogi_dedomenon (foititis *foit){

    printf( :);gets(foit -> onoma);puts( :);scanf(%d, &foit -> AM);printf( );scanf(%d, &foit -> v_askiseon);printf( );scanf(%d, &foit -> v_graptou);

    }/* eisagogi_dedomenon*/

  • C .

    #define N 100typedef struct{

    char minas [10];short imera;short etos;

    }imer_nia;

  • typedef struct{

    char omoma;imer_nia imer_gen;char fylo;int AT;

    }typos_atomou;

    typos_atomou

    typos_atomou atoma [N];

  • . :

    = 0.3 + 0.7

    = , = = . . , () .

  • :

    1. ()2. 3. 4. 5.

  • #define PLITHOS 200 /* */#define MHKOS 20#define ASKHSEIS 5 /* */typedef enum /* */{

    YEYDHS, ALITHIS;}Logikos;

  • typedef struct{

    int AM;char onoma [MHKOS];int v_askiseon [ASKHSEIS];int v_graptou;int v_telikos;

    } typos_domis;

  • epiloges

    /* : epiloges :

    . : : */

  • void epiloges (int *epilogi){

    printf (\n);printf ( 1: \n);printf ( 2: \n);printf (

    -- 3: \n);printf ( 4: \n);printf ( 5: \n);scanf(%d, epilogi); /* scanf(%d, &*epilogi); */

    }

  • diavase

    /* : diavase : . : . : . */

    void diavase (typos_domis pinakas[ ], int *megethos,Logikos *dimiourgia)

    {int i;char synexeia = n, nea_grammi;*dimiourgia = YEYDHS; *megethos = -1;

  • while (synexeia == n || synexeia == N){

    *megethos = *megethos +1;printf (\n E :);scanf (%d, &pinakas [*megethos] .AM;scanf (%c, &nea_grammi); /* \n */printf (\n :);gets (pinakas [*megethos] .onoma);printf (\n %d ,

    ASKHSEIS);for (i = 0; i < ASKHSEIS; ++i)

    scanf (%d, &pinakas [*megethos] .v_askiseon[i]);

  • printf (\n E );scanf (%d, &pinakas [*megethos] .v_graptou);scanf (%c, &nea_grammi); /* \n */printf (\n ; (n/o));synexeia = getchar ();

    }*dimiourgia = ALITHIS;*megethos = *megethos +1; /* */

    }

  • telikos_vathmos/* : telikos_vathmos : . : pinakas. : pinakas. */

    void telikos_vathmos (typos_domis pinakas[ ], int megethos,Logikos dimiourgia)

    {int i;if (dimiourgia ==ALITHIS)

    for ( i=0; i< megethos; ++i)tel_vath_domis(&pinakas[i]);

  • elseprintf(\n );

    } tel_vath_domis :

    tel_vath_domis

    /* : tel_vath_domis : . : . : . */

  • void tel_vath_domis (typos_domis *domi){

    int i;double mesos;/* */mesos = 0.0;for (i = 0; i < ASKHSEIS; ++i)

    mesos += domi -> v_askiseon [i];mesos /= ASKHSEIS;/* */domi -> v_telikos = 0.3 * mesos + 0.7 * domi ->v_graptou;

    }

  • , .

    taxinomisi

    /* : taxinomisi : . : ,

    . : . */

  • void taxinomisi (typos_domis pinakas [ ], int megethos,Logikos dimiourgia)

    {if (dimiourgia == ALITHIS){

    tax_pinaka (pinakas, megethos);printf ( . \n);

    }else

    printf ( . \n);}

  • tax_pinaka

    /* : tax_pinaka :

    . : . :

    . */void tax_pinaka (typos_domis pinakas [ ], int megethos){

    int i;char taxinomisi = o;do{

  • taxinomisi = n;for (i = 0; i < megethos-1; ++i)

    if (pinakas [i]. AM > pinakas [i+1]. AM){

    andallagi (&pinakas [i], &pinakas [i+1]);taxinomisi = o;

    }megethos--;

    }while (taxinomisi == o);}

  • andallagi

    /* : andallagi : . : . : . */

    void andallagi (typos_domis *domi_1, *domi_2){

    typos_domis pros;

    pros = *domi_1;*domi_1 = *domi_2;*domi_2 = pros;

    }

  • anazitisi

    /* : anazitisi :

    . : . :

    . */

    void anazitisi (typos_domis pinakas[ ], int megethos,Logikos dimiourgia)

    {int i, thesi, kleidi;

  • Logikos epityxia;if (dimiourgia == ALITHIS){

    printf ( :);scanf (%d, &kleidi);anaz_pinaka (kleidi, pinakas, megethos, &epityxia, &thesi)if (epityxia == ALITHIS){

    printf (\n );printf (:%d\n, pinakas [thesi] .AM);printf (: %s\n, pinakas [thesi] .onoma);printf ( :);

  • for (i = 0; i < ASKHSEIS; ++i)printf (%d, pinakas [thesi] .v_askiseon [i]);

    printf (\n : %d\n,pinakas [thesi] .v_graptou);

    printf ( : %d\n,pinakas [thesi] .v_telikos);

    }else

    printf (\n %d .\n, kleidi);

    }else

    printf (\n . \n);}

  • void anaz_pinaka (int kleidi, typos_domis pinakas [ ],int megethos, Logikos *epityxia, int *thesi)

    {int arxi, telos, mesaio;*epityxia = YEYDHS;*thesi = -1;arxi = 0;telos = megethos-1;while (arxi

  • if (pinakas [mesaio] .AM = = kleidi){

    *thesi = mesaio;*epityxia = ALITHIS;

    }else

    if (kleidi < pinakas [mesaio] .AM)telos = mesaio-1;

    elsearxi = mesaio +1;

    }/* while */}/* anaz_pinaka */

  • typose

    /* : typose : . : . */

  • void typose (typos_domis pinakas[ ], int megethos,Logikos dimiourgia)

    {if (dimiourgia == ALITHIS){

    printf ( \n);ektyposi (pinakas, megethos);printf (\n);

    }else

    printf ( .\n);}

  • /* : ektyposi : : . */

    void ektyposi (typos_domis pinakas[ ], int megethos){

    int i;printf(AM \n);for (i = 0; i < megethos; ++i)

    printf (%d %d\n, pinakas [i] .AM, pinakas [i] .v_telikos);}

  • main

    /* : . :

    , , .

    : . : . */

  • #include #include#define PLITHOS 200 /* */#define MHKOS 20#define ASKHSEIS 5 /* */

    /* */typedef enum{

    YEYDHS, ALITHIS;} Logikos;

  • typedef struct{

    int AM;char onoma [MHKOS];int v_askiseon[ASKHSEIS];int v_graptou;int v_telikos;

    }typos_domis;/* */void epiloges (int *epilogi);void diavase (typos_domis pinakas [ ], int *megethos,

    Logikos *dimiourgia);

  • void telikos_vathmos (typos_domis pinakas [ ], int megethos,Logikos dimiourgia);

    void taxinomisi (typos_domis pinakas [ ], int megethos, Logikosdimiourgia);

    void anazitisi (typos_domis pinakas [ ], int megethos, Logikosdimiourgia);

    void typose (typos_domis pinakas [ ], int megethos, Logikosdimiourgia);

    void tel_vath_domis (typos_domis *domi);void tax_pinaka (typos_domis pinakas [ ], int megethos);void anaz_pinaka (int kleidi, typos_domis pinakas [ ],

    int megethos, Logikos *epityxia, int *thesi);void ektyposi (typos_domis pinakas [ ], int megethos);

  • int main (void){

    /* */typos_domis pinakas_foit [PLITHOS];int megethos, epilogi;Logikos epexergasia = ALTHIS, dimiourgia = YEYDHS;/* */while (epexergasia = = ALTHIS){

    epiloges (epilogi);switch (epilogi)

  • {case 1:

    diavase (pinakas_foit, &megethos, &dimiourgia);break;

    case 2:typose (pinakas_foit, megethos, dimiourgia);break;

    case 3:telikos_vathmos (pinakas_foit, megethos, dimiourgia);taxinomisi (pinakas_foit, megethos, dimiourgia);break;

  • case 4:anazitisi (pinakas_foit, megethos, dimiourgia);break;

    case 5:epexergasia = YEYDHS;printf ( );break;

    default :printf ( . .\n);

    } /* switch */} /* while */return 0;

    } /* main */

  • (text files)

    .

    ( , ). . .

    .

    (record) .

  • (text file) (binary file). .

    .

    (streams) bytes .

    stdio.

  • stdout.

    , , stderr.

    FILE *_1, *_2, *_3;

    FILE *arxeio;

    __=fopen(__, _);

  • __ : a:foitites.txt

    r, .

    , fopen .

    w,

    .

    a,

    .

    r+,

    ( )

  • w+,

    .

    a+,

    .

    a:eisodos.txt. .

    #define onoma_arxeiou a:eisodos.txt

    FILE *dedomena;

    dedomena = fopen( onoma_arxeiou, r);

  • . .

    char eis_arxeio[20], ex_arxeio[20];FILE *eis_dedomena, *ex_dedomena;

    printf( );gets(ex_arxeio);printf( );gets(eis_arxeio);eis_dedomena = fopen(eis_arxeio, r);ex_dedomena = fopen(ex_arxeio, w);

  • , .

    #include

    ..

    If ((eis_dedomena = fopen(eis_arxeio, r)) ==NULL){

    printf( %s, eis_arxeio);exit(-1);

    }

  • fclose(__);

    .

    .

    .

  • :

    FILE *foitites_arxeio;

    foitites_arxeio = fopen(a:foit.dat, w);/* */

    fclose(foitites_arxeio);foitites_arxeio = fopen(a: foit.dat, r);/* */

    fclose(foitites_arxeio);

    feof

    feof(__);

  • /*

    foititis_arxeio */

    while ( !feof(foititis_arxeio) ){

    /* */

    /*

    foititis_arxeio */

    } /* while */

  • .

    \n .

    .

    - - .

  • fprintf(__, _, );fputc(, __);fputs(, __);

    int ar1=5, ar2=15;

    double ar3=14.25;

    char xar1=x, xar2=y;

    char seira[20]= Programmatismos;

  • fprintf(exodos, %d\n, ar1); 5fprintf(exodos, %d %d\n, ar1, ar2); 5 15fprintf(exodos, %c%c\n, xar1, xar2); xy

    fputc(xar1, exodos);fputc(xar2, exodos); xyfputc(\n, exodos);

  • fputs(seira, exodos);fputs(\n, exodos); Programmatismos

    , .

  • void dimiourgia_arxeiou (char on_arxeiou[]){

    FILE *exodos;

    int akeraios;

    if ((exodos =fopen(on_arxeiou, w))==NULL){

    fprintf(stderr, %s, on_arxeiou);

    exit(-1);}

  • printf( ( 0 ) :);scanf(%d, &akeraios);while (akeraios !=0){fprintf(exodos, %d\n, akeraios);printf( ( 0 ) :);scanf(%d, &akeraios);

    }fclose(exodos);

    }/* dimiourgia_arxeiou */

  • , .

    void dimiourgia_arx_xarakthron(char on_arxeiou[]){

    FILE *arx_xar;

    char xar;

    if ((arx_xar=fopen(on_arxeiou, w))==NULL){fprintf(stderr, : %s,

    on_arxeiou);exit(-1);

    }

  • printf(\n ( \ ) :);scanf(%c, xar);while (xar != \\) /* \ \\ */{

    fputc(xar, arx_xar);if (xar==\n)printf(\n ( \

    ) :);scanf(%c, xar);

    }fclose(arx_xar);

    }

  • dimiourgia_arx_xarakthron.

    void dimiourgia_arx_xarakthron(char on_arxeiou[]);int main(void){ char onoma_arxeiou[20];

    printf(\n :);gets(onoma_arxeiou);printf(\n %s,

    onoma_arxeiou);dimiourgia_arx_xaraktiron(onoma_arxeiou);printf(\n %s );return 0; }

  • :

    fscanf(__, / , );fgetc(__);fgets(, , __);

  • . , .

    void mesi_timi(char onoma_arxeiou[]){

    FILE *arxeio;

    int arithmos, athroisma, plithos;

    int mesos_oros;

  • athroisma=0; plithos =0;

    if ((arxeio=fopen(onoma_arxeiou, r))==NULL){printf(stderr, :

    %s, onoma_arxeiou);exit(-1); }

    fscanf(arxeio, &arithmos);while (!feof(arxeio)){

    athroisma += arithmos;

    plithos ++;

    fscanf(arxeio, arithmos);}

  • fclose(arxeio);if (plithos ==0)

    mesos_oros = 0;

    else

    mesos_oros /= plithos;

    printf(\n : %d, plithos);printf(\n : %d, mesos_oros);

    }

    , dimiourgia_arxeiou mesi_timi.

  • #include

    #include

    void dimiourgia_arxeiou(char on_arxeiou[]);void mesi_timi(char onoma_arxeiou[]);int main(void){

    char on_arxeiou[20];printf(\n :);gets(on_arxeiou);

    printf(\n : %s, on_arxeiou);dimiourgia_arxeiou(on_arxeiou);printf(\n %s , on_arxeiou);

  • printf(\n %s, on_arxeiou);mesi_timi(on_arxeiou);return 0;

    }

    14.3515.6517.85

    .

    fscanf(eisodos, %6lf%4lf%5lf, &x, &y, &z);

    x=14.351 y=5.65 z=17.85

  • abcd, 50, 60, 70

    ,

    1. fscanf(eisodos, %4s%c%d%c%d%c%d, onoma, &xar, &x, &xar,&y, &xar, &z);

    2. fscanf(eisodos, %4s, %d, %d, %d, onoma, &x, &y, &z);3. fscanf(eisodos, %4s%*c%d%*c%d%*c%d, onoma, &x, &y, &z);

    onoma=abcd x=50 y=60 z=70

  • .

    .

  • #include

    #include

    void antigrafi_arxeiou(char arxeio_1[], arxeio_2[]);int main(void){

    char eis_arxeio[20], ex_arxeio[20];printf(\n :);gets(eis_arxeio);printf(\n :);gets(ex_arxeio);antigrafi_arxeiou(eis_arxeio, ex_arxeio);return 0; }

  • void antigrafi_arxeiou(char arxeio_1[], arxeio_2[]){

    FILE *eisodos, *exodos;

    char xar;

    if ((eisodos=fopen(arxeio_1, r))==NULL) {fprintf(stderr, :%s, arxeio_1);exit(-1);}if ((exodos=fopen(arxeio_2, w))==NULL){fprintf(stderr, :%s, arxeio_2);exit(-1);}

  • xar=fgetc(eisodos);while (!feof(eisodos)){

    fputc(exodos);xar=fgetc(eisodos);

    }fclose(eisodos);fclose(exodos);

    }/* antigrafi_arxeiou */

  • (binary files)

    .

    .

    .

    .

    fopen.

    fclose.

    feof.

  • fwrite(, , , __); .

    .

    FILE *ex_arxeio;

    int akeraios =5;

    fwrite(&akeraios, sizeof(akeraios), 1, ex_arxeio); akeraios ex_arxeio.

  • , .

    void dimiourgia_dyadikou_arxeiou(char on_arxeiou[]){

    FILE *ex_arxeio;

    int akeraios;

    if ((ex_arxeio=fopen(on_arxeiou, w))==NULL){fprintf(stderr, : %s, on_arxeiou);exit(-1);

    }

  • printf(\n (0 ) :);scanf(%d, &akeraios);while (akeraios !=0){

    fwrite(&akeraios, sizeof(akeraios), 1, ex_arxeio);printf(\n (0 ):);scanf(%d, &akeraios);

    }fclose(ex_arxeio);

    }

  • .

    .

    fread(, , , __);

    FILE *eis_arxeio;

    int akeraios;

    eis_arxeio=fopen(on_arxeiou, r);

    fread(&akeraios, sizeof(akeraios), 1, eis_arxeio);

  • .

    void ektyposi_dyadikou_arxeiou_aker(char on_arxeiou[]){

    FILE *eis_arxeio;

    int akeraios;

    if ((eis_arxeio=fopen(on_arxeiou, r))==NULL){

    fprintf(stderr, : %s, on_arxeiou);exit(-1);

    }

  • fread(&akeraios, sizeof(akeraios), 1, eis_arxeio);while (!feof(eis_arxeio)){

    printf(\n%d, akeraios);fread(&akeraios, sizeof(akeraios), 1, eis_arxeio);

    }fclose(eis_arxeio);

    }/* ektyposi_dyadikou_arxeiou_aker */

    . :

    () (), () , () .

  • #include

    #include

    /* */

    typedef struct

    {int AM;

    char onoma[30];double vathmos;

    }typos_eggrafis;/* */

    void dimiourgia_arxeiou(char arxeio[]);void ektyposi_arxeiou(char arxeio[]);

  • int main(void){

    char on_arxeiou[20];printf(\n

    :);gets(on_arxeiou);dimiourgia_arxeiou(on_arxeiou);printf(\n : %s, on_arxeiou);printf(\n %s :, on_arxeiou);ektyposi_arxeiou(on_arxeiou);return 0;

    }

  • void dimiourgia_arxeiou(char arxeio[]){

    FILE *ex_arxeio;

    typos_eggrafis foititis;

    char xar; /* \n */

    if ((ex_arxeio=fopen(arxeio, w))==NULL){

    fprintf(stderr, \n : %s, arxeio);exit(-1);

    }printf(\n (0 ) :);scanf(%d, &foititis.AM);

  • scanf(%c, &xar); /* \n */while (foititis.AM != 0){

    printf(\n :);gets(foititis.onoma);printf(\n :);scanf(%lf, &foititis.vathmos);/* */

    fwrite(&foititis, sizeof(foititis), 1, ex_arxeio);printf(\n (0 ) :);scanf(%d, &foititis.AM); scanf(%c, &xar);

    }/* while */fclose(ex_arxeio); } /* dimiourgia_arxeiou */

  • void ektyposi_arxeiou(char on_arxeiou[]){

    FILE *ex_arxeio;

    typos_eggrafis foititis;

    if ((ex_arxeio=fopen(on_arxeiou, r))==NULL){

    fprintf(stderr, \n :%s,on_arxeiou);

    exit(-1);}/* */

    fread(&foititis, sizeof(foititis), 1, ex_arxeio);

  • while (!feof(ex_arxeio)){

    printf(\n : %d, foititis.AM);printf(\n : %s, foititis.onoma);printf(\n : %lf, foititis.vathmos);fread(&foititis, sizeof(foititis), 1, ex_arxeio);

    }fclose(ex_arxeio);

    }

  • . :

    1. 2. 3. 4. .

    .

  • #include #include enum fylo { andras, gynaika };typedef struct{

    int AM;char onoma[15];enum fylo foit_fylo;int vathmos;

    }typos_egrafis;

  • void diaxorismos (char arxeio_t[], char arxeio_a[],char arxeio_g[]);

    int main (void){

    char arxeio_t[20];char arxeio_a[20];char arxeio_g[20];printf (\n

    :);gets (arxeio_t);

  • printf (\n :);

    gets (arxeio_a);printf (\n :);gets (arxeio_g);diaxorismos (arxeio_t, arxeio_a, arxeio_g);return 0;

    }void diaxorismos (char arxeio_t[], char arxeio_a[],

    char arxeio_g[]){

    FILE *tmima, *andres, *gynaikes;typos_egrafis foititis;

  • if ((tmima=fopen (arxeio_t, r)) == NULL){

    fprintf (stderr, : %s,arxeio_t);

    exit (-1);}if ((andres=fopen (arxeio_a, w)) == NULL){

    fprintf (stderr, : %s,arxeio_a);

    exit (-1);}

  • if ((gynaikes=fopen (arxeio_g, w)) == NULL) {fprintf (stderr, : %s,

    arxeio_g);exit (-1);

    }fread (&foititis, sizeof(foititis), 1, tmima);while (!feof(tmima)) {

    if (foititis.foit_fylo == gynaika)fwrite (&foititis, sizeof(foititis), 1, gynaikes);

    elsefwrite (&foititis, sizeof(foititis), 1, andres);

    fread (&foititis, sizeof(foititis), 1, tmima);} /* while*/

  • fclose (tmima);fclose (andres);fclose (gynaikes);

    }

  • (merging)

    . . () , ( (merging) ).

  • 1. .2. .

    3. :3.1

    :

    . .

  • : . .

    4. .

    5. .

  • #include #include enum fylo { andras, gynaika };typedef struct{

    int AM;char onoma[15];enum fylo foit_fylo;int vathmos;

    }typos_egrafis;

  • void syghonefsi (char arxeio_t[ ], char arxeio_a[ ],char arxeio_g[ ]);int main (void){

    char arxeio_t[20];char arxeio_a[20];char arxeio_g[20];printf (\n :);gets (arxeio_a);

  • printf (\n :);gets (arxeio_g);printf (\n

    :);gets (arxeio_t);syghonefsi (arxeio_t, arxeio_a, arxeio_g);return 0;

    }void syghonefsi (char arxeio_t[ ], arxeio_a[ ], arxeio_g[ ]);{

    FILE *tmima, *andres, *gynaikes;typos_egrafis foititis, foititria;

  • if ((tmima=fopen (arxeio_t, w)) == NULL){

    fprintf (stderr, : %s,arxeio_t);

    exit (-1);}if ((andres=fopen (arxeio_a, r)) == NULL){

    fprintf (stderr, : %s,arxeio_a);

    exit (-1);}

  • if ((gynaikes=fopen (arxeio_g, r)) == NULL){

    fprintf (stderr, : %s,arxeio_g);

    exit (-1);}/* */fread (&foititis, sizeof(foititis), 1, andres);fread (&foititria, sizeof(foititria), 1, gynaikes);

  • while (!feof(andres) && !feof (gynaikes))if (foititis.AM < foititria.AM){

    fwrite (&foititis, sizeof(foititis), 1, andres);fread (&foititis, sizeof(foititis), 1, tmima);

    }else{

    fwrite (&foititria, sizeof(foititria), 1, gynaikes);fread (&foititria, sizeof(foititria), 1, tmima);

    }/* */

  • while (!feof(andres)){

    fwrite (&foititis, sizeof(foititis), 1, tmima);fread (&foititis, sizeof(foititis), 1, andres);

    }/* */while (!feof(gynaikes)){

    fwrite (&foititria, sizeof(foititria), 1, tmima);fread (&foititria, sizeof(foititria), 1, gynaikes);

    }fclose(tmima); fclose(andres); fclose(gynaikes); }

  • (master file) :

    1. , 2. , 3. .

    (transaction file), :

    1. 2. .

    . .

  • 1 basiko_arx

    eggr_basikou.2 kinisis_arx

    eggr_kinisis.3 kinisis_arx

    :

    3.1 eggr_basikou eggr_kinisis. :

    eggr_basikou eggr_kinisis. kinisis_arx.

    : eggr_basikou . basiko_arx.

  • 3 . .

    4 eggr_basikou , .

    5 basiko_arx .

  • :

    12300 . 1250012310 . 750013320 . 2280013400 . 013450 . 630013490 . 1280014000 . 2550014010 . 380014040 . 170014100 . 18500

  • :12300 100012300 240012310 170012310 50012310 30012310 100013400 280013450 30013450 250013450 10013450 130014010 220014010 50014010 120014010 700

  • :

    12300 . 1590012310 . 1100013320 . 2280013400 . 280013450 . 1050013490 . 1280014000 . 2550014010 . 840014040 . 170014100 . 18500

  • /* */#include #include /* */typedef struct{

    int kodikos;char onoma[20];int poso;

    }eggrafi_basikou;

  • /* */typedef struct{

    int trexon_kodikos;int trexon_poso;

    }eggrafi_kinisis;void enimerosi (char basiko_arx[ ], char kinisis_arx[ ],

    char neo_arx[ ]);int main (void){

    char basiko_arx[20];char kinisis_arx[20];char neo_arx[20];

  • printf (\n :);gets (basiko_arx);printf (\n :);gets (kinisis_arx);printf (\n :);gets (neo_arx);enimerosi (basiko_arx, kinisis_arx, neo_arx);return 0;

    }/* . */

  • void enimerosi (char basiko_arx[], char kinisis_arx[ ],char neo_arx[ ])

    {FILE *basiko, *kinisis, *neo;eggrafi_basikou eggr_basikou;eggrafi_kinisis eggr_kinisis;

    if ((basiko=fopen(basiko_arx, r)) == NULL){

    fprint(stderr, : %s,basiko_arx);

    exit(-1);}

  • if ((kinisis=fopen(kinisis_arx, r)) == NULL){

    fprint(stderr, : %s,kinisis_arx);

    exit(-1);}if ((neo=fopen(neo_arx, w)) == NULL){

    fprint(stderr, : %s,neo_arx);

    exit(-1);}

  • /* */

    fread(&eggr_basikou, sizeof(eggr_basikou), 1, basiko);fread(&eggr_kinisis, sizeof(eggr_kinisis), 1, kinisis);

    /* */eggr_basikou.poso = 0;while (!feof(kinisis)) {

    /* */if (eggr_basikou.kodikos == eggr_kinisis.trexon_kodikos)

  • {eggr_basikou.poso += eggr_kinisis.trexon_poso;fread(&eggr_kinisis, sizeof(eggr_kinisis), 1, kinisis);

    }else{

    fwrite(&eggr_basikou, sizeof(eggr_basikou), 1, neo);fread(&eggr_basikou, sizeof(eggr_basikou),1,basiko);

    }} /*while*//* , */

  • fwrite(&eggr_basikou, sizeof(eggr_basikou), 1, neo);

    /* */fread(&eggr_basikou, sizeof(eggr_basikou), 1, basiko);while (!feof(basiko)){

    fwrite(&eggr_basikou, sizeof(eggr_basikou), 1, neo);fread(&eggr_basikou, sizeof(eggr_basikou), 1, basiko);

    }fclose(neo); fclose(basiko); fclose(kinisis);

    }

  • (merge sort)

    : 12 23 2 3 9 54 34 4 67 11 32 69 1: 12 23 34 11 32 69 2: 2 3 9 54 4 67

    1: 12 23 34 11 32 69 2: 2 3 9 54 4 67 : 2 3 9 12 23 34 54 4 11 32 67 69

  • : 2 3 9 12 23 34 54 4 11 32 67 69 1: 2 3 9 12 23 34 54 2: 4 11 32 67 69

    1: 2 3 9 12 23 34 54 2: 4 11 32 67 69 : 2 3 4 9 11 12 23 32 54 67 69

  • 1 .

    2 :

    2.1 1 : 1, .

    2.2 , 2 .

  • 1 1 2 . .

    2 1 2 :2.1 ,

    1 2, :

  • 2.1.1 1 2,

    1

    2 .

  • 2.2 1

    2

    1 .

    3 1 2 .

  • /* T . */#include #include typedef struct{

    float kleidi;} typos_egrafis;void antigrafi(char on_arxeioa[ ], on_arxeiob[ ], int *telos)void taxinomisi(char on_arxiko[ ]);void katanomi(char on_arxiko[ ], on_pros1[ ], on_pros2[ ]);

  • void syghonefsi(char on_arxiko[ ], on_pros1[ ], on_pros2[ ], int*treximata);

    void antigrafi_trex(char on_apo[ ], on_pros[ ], typos_egrafis*egrafi, int *plithos_trex);

    void ektyposi(char on_arxeio);int main(void){

    char on_arxiko[20];FILE *arxiko, *pros1, *pros2;typos_egrafis egrafi;long t0, t1;/* t0 = , t1 = *//* */

  • printf(\n :);gets(on_arxiko);/* */printf(\n *** ***);ektyposi(on_arxiko);/* = 1 */time(&t0); /* */taxinomisi(on_arxiko);time(&t1);printf(\n : %d, t1-t0);/* */printf(\n *** ***);

  • ektyposi(on_arxiko);} /* main */

    void taxinomisi(char on_arxiko[ ]){

    int treximata;char on_pros1[20], on_pros2[20];

    treximata = 0;printf(\n 1:);gets(on_pros1);printf(\n 2:);gets(on_pros2);

  • do{

    katanomi(on_arxiko, on_pros1, on_pros2);syghonefsi(on_arxiko, on_pros1, on_pros2, *treximata);

    } while (treximata > 1);} /* taxinomisi */

    /* 1 2 */void katanomi(char on_arxiko[ ], on_pros1[ ], on_pros2[ ]){

    typos_egrafis egrafi;FILE *arxiko, *pros1, *pros2;

  • if ((arxiko = fopen(on_arxikou, r)) == NULL){

    fprintf(stderr, : %s,on_arxikou);

    exit(-1);}if ((pros1 = fopen(on_pros1, w)) == NULL){

    fprintf(stderr, : %s,on_pros1);

    exit(-1);}

  • if ((pros2 = fopen(on_pros2, w)) == NULL){

    fprintf(stderr, : %s,on_pros2);

    exit(-1);}/* */fread(&egrafi, sizeof(egrafi), 1, arxiko);while (!feof(arxiko)){

    antigrafi_trex(arxiko, pros1, &egrafi);if (feof(arxiko)) break;antigrafi_trex(arxiko, pros2, &egrafi);

    }

  • fclose(arxiko);fclose(pros1);fclose(pros2);

    } /* katanomi */

    /* apo pros */void antigrafi_trex(FILE *apo, *pros, typos_egrafis *egrafi, int

    *plithos_trex){

    typos_egrafis palia;

    do{

    fwrite(egrafi, sizeof(egrafi), 1, pros);

  • palia = *egrafi;fread(egrafi, sizeof(egrafi), 1, apo);

    } while (!feof(apo)) && !(egrafi ->kleidi < palia.kleidi);(*plithos_trex)++;

    }

    /* 1 2 */void syghonefsi(char on_arxiko[ ], on_pros1[ ], on_pros2[ ], int

    *treximata){

    typos_egrafis egrafi1, egrafi2, palia;*treximata = 0;

  • if ((arxiko = fopen(on_arxiko, w)) == NULL){

    fprintf(stderr, : %s,on_arxiko);

    exit(-1);}if ((pros1 = fopen(on_pros1, r)) == NULL){

    fprintf(stderr, : %s,on_pros1);

    exit(-1);}

  • if ((pros2 = fopen(on_pros2, r)) == NULL){

    fprintf(stderr, :%s,on_pros2);exit(-1);

    }fread(&egrafi1, sizeof(egrafi1), 1, pros1);fread(&egrafi2, sizeof(egrafi2), 1, pros2);while (!feof(pros1) && !feof(pros2)){

    if (egrafi1.kleidi < egrafi2.kleidi){

    fwrite(&egrafi1, sizeof(egrafi1), 1, arxiko);palia = egrafi1;

  • fread(&egrafi1, sizeof(egrafi1), 1, pros1);if (feof(pros1)) || egrafi1.kleidi < palia.kleidi

    antigrafi_trex(pros2, arxiko, &egrafi2, treximata);}else{

    fwrite(&egrafi2, sizeof(egrafi2), 1, arxiko);palia = egrafi2;fread(&egrafi2, sizeof(egrafi2), 1, arxiko);if (feof(pros2)) || egrafi2.kleidi < palia.kleidi

    antigrafi_trex(pros1, arxiko, &egrafi1, treximata);}

    } /* while */

  • /* pros1 pros2 arxiko */while (!feof(pros1))

    antigrafi_trex(pros1, arxiko, &egrafi1, treximata);while (!feof(pros2))

    antigrafi_trex(pros2, arxiko, &egrafi2, treximata);fclose(arxiko);fclose(pros1);fclose(pros2);

    } /* syghonefsi */void ektyposi(char on_arxiko[ ]){

    typos_egrafis egrafi;

  • FILE *arxiko;if ((arxiko = fopen(on_arxiko, r)) == NULL){

    fprintf(stderr, : %s,on_arxiko);

    exit(-1);}i = 0;while (fread(&egrafi, sizeof(egrafi), 1, arxiko) > 0){

    printf(8.2f, egrafi.kleidi);i++;

  • if (i == 10){

    printf(/n);i = 0;

    }}close(arxiko);

    } /* ektyposi */

  • , (sequential) (random) . .

    .

    .

    fseek ftell

  • ftell( __)fseek(__, , )

    : SEEK_SET, SEEK_END, SEEK_CUR

    arxeio=fopen(on_arxeiou, r);

    10 5 20 15 32

    0 1 2 3 4 5 6 7 8 9 10

    byte

  • 10 5 20 15 32

    0 1 2 3 4 5 6 7 8 9 10

    byte

    ftell(arxeio) 0.

    fseek(arxeio, sizeof(int), SEEK_CUR);fread(&arithmos, sizeof(int), 1, arxeio);

    arithmos=5

  • fseek(arxeio, 0, SEEK_SET); .

    fseek(arxeio, 0, SEEK_END); ( ).

    ftell(arxeio) 10 .

    = 10/2

  • _ = _ * _

    _ = byte .

    _ = 0, 1, 2,

    _ = bytes

    .

    arith_eggr

    fseek(arxeio, arith_eggr * sizeof(int), SEEK_SET);fread(&arithmos, sizeof(int), 1, arxeio);

  • .

    fseek(arxeio, 0, SEEK_END);mikos_arxeiou = ftell(arxeio);plithos_eggrafon = mikos_arxeiou / sizeof(eggrafi);

  • ( ) . :

    , .

    ,

    .

  • typedef struct

    {char onoma[20];int AM;

    int vathmos;

    }typos_eggrafis;

  • void akolouthiaki_anaz(char on_arxeiou, int kleidi, int *thesi,*vrethike)

    {FILE *arxeio;

    typos_eggrafis foititis;

    if ((arxeio=fopen(on_arxeiou, r))==NULL){

    fprintf(stderr, : %s,on_arxeiou);

    exit(-1); }

  • *thesi = 0; *vrethike = 0;

    fread(&foititis, sizeof(foititis), 1, arxeio);while (!feof(arxeio) && !*vrethike ){

    if (foititis.AM ==kleidi)*vrethike=1;

    else {thesi = ftell(arxeio);fread(&foititis, sizeof(foititis), 1, arxeio);

    } /* if */} /* while */ } /* akolouthiaki_anaz */

  • : .

    void dyadiki_anaz(char on_arxeiou, int kleidi, int *thesi, int *vrethike){

    FILE *arxeio;

    int proti, teleytaia, mesaia, plithos;

    typos_eggrafis foititis;

    if ((arxeio=fopen(on_arxeiou, r))==NULL) {fprint(stderr, : %s,

    on_arxeiou);exit(-1);

    }

  • proti =0;

    /* */

    fseek(arxeio, 0, SEEK_END);/* */

    plithos = ftell(arxeio) / sizeof(foititis);teleytaia = plithos -1;

    *vrethike = 0;

    while (proti

  • if ( kleidi < foititis.AM)teleytaia = mesaia -1;

    else

    if (kleidi > foititis.AM)proti = mesaia +1;

    else

    {*vrethike = 1;

    *thesi = mesaia;

    }} /* while */

    } /* dyadiki_anaz */

  • :

    , () . .

    , , .

    .

    .

  • foit_arxeiozitoumenos thesi evretirio[thesi]

    14586 0 10987 0 10987

    1 11562 1 11562

    2 11734 2 11734

    3 12635 3 12635

    ... . . . ..

    150 14586 150 14586

    . . . .. ..

  • foit_arxeio

    0 109871 115672 117343 126354 127825 129536 13001

    0 12782 7 131511 13933 8 131832 14180 9 13933

    21500 ... . 10 1410111 14132

    60 21500 12 14144... . 13 14154

    14 14180

    zitoumenos

    thesi evretirio[thesi]

  • foit_arxeio

    .. .

    300 20155301 20200302 20800303 20981304 21500. ..

  • /***************************************************/ :.

    : .

    : .

    :, , .

    /***************************************************/

  • #include #include #define N 1000typedef struct {

    char onoma [20];int AM;int vathmos;

    }typos_egrafis;void dimiourgia_evretiriou (FILE *foit_arxeio, int evretirio[], int *plithos);void dyadiki_anazitisi (int evretirio[],int plithos,int kleidi,int *vrethike,

    int *thesi);int main (void){

    char on_arxeiou [25];

  • FILE *foit_arxeio;typos_egrafis foititis;typos_egrafis evretirio[N];int kleidi, plithos, thesi, arithmos_egr, vrethike;int SIZE = sizeof (typos_egrafis);printf(\n :);gets(on_arxeiou);if ((foit_arxeio = fopen(on_arxeiou, r) == NULL){

    fprintf(stderr, : %s,on_arxeiou);exit (-1);

    }

  • dimiourgia_evretiriou(foit_arxeio, evretirio, &plithos);printf(\n :);printf(\n

    :);scanf(%d, &kleidi);while(kleidi > 0){

    dyadiki_anazitisi(evretirio, plithos, kleidi, &vrethike, &thesi);if (!vrethike)

    printf(\n : %d,kleidi);

    else

  • {fseek(foit_arxeio, thesi*SIZE, SEEK_SET);fread(&foititis, SIZE, 1, foit_arxeio);printf(\n AM: %d, : %s, foititis.AM,

    foititis.onoma);printf(\n :);scanf(%d, &foititis.vathmos);/* */fseek(foit_arxeio, -SIZE, SEEK_CUR);fwrite(&foititis, SIZE, 1, foit_arxeio);

    }/* if */printf(\n\n

    :);

  • printf(\n\n :);

    scanf(%d, &kleidi);} /* while */printf(\n );fclose (foit_arxeio);

    }/* (index) , foit_arxeio */void dimiourgia_evretiriou (FILE *foit_arxeio, int evretirio[],

    int *plithos){

    typos_egrafis foititis;

  • *plithos = -1;fseek(foit_arxeio, 0, SEEK_SET);fread(&foititis, SIZE, 1, foit_arxeio);while (!feof(foit_arxeio)){

    *plithos = *plithos +1;evretirio[*plithos] = foititis.AM;fread(&foititis, SIZE, 1, foit_arxeio);

    } /* while */}/* = kleidi */

  • void dyadiki_anazitisi (int evretirio[], int plithos, int kleidi,int *vrethike, int *thesi)

    {int proto, mesaio, teleytaio;proto = 0;teleftaio = plithos - 1;*vrethike = 0;while (proto

  • elseif (kleidi > evretirio[mesaio])

    proto = mesaio + 1;else{

    *vrethike = 1;*thesi = mesaio;

    }} /* while */

    }

  • ,

  • :

    :. .

    )

    typedef ... typos_stoixeiou ;typedef struct typos_komvou *typos_deikti;

    typedef struct typos_komvou{

    typos_stoixeiou dedomena;typos_deikti epomenos;

    };typos_deikti lista;

    , C.

  • :

    :. .

    ) typedef ... typos_stoixeiou ;

    typedef struct typos_komvou{

    typos_stoixeiou dedomena;typos_komvou *epomenos;

    };

    typos_komvou *lista;

  • typedef struct typos_komvou *typos_deikti;struct typos_komvou{

    char on_epiv[15];int thesi;typos_deikti epomenos;

    };typos_deikti lista_epiv;

  • lista_epivon_epiv thesi

    epomenos

    lista_epiv

    lista_epiv -> on_epiv on_epiv .

    lista_epiv -> thesi thesi .

    lista_epiv -> epomenos H .

    lista_epiv -> epomenos -> thesi thesi .

    lista_epiv -> epomenos -> epomenos -> epomenos=NULL;

  • , lista_epiv.

    A

    1. trexon = lista_epiv2