Cibernetica si Informatica Economica (Laborator cu exemple)

Embed Size (px)

Citation preview

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    1/83

    ... 4 1.

    C. , .. 5 2.

    , , ... 16 3.

    .. 23 4.

    .... 34 5.

    ...... 43 6.

    , .................... 53 7.

    main()......... 66 8.

    .. 70 9.

    . 76 1.

    ............................................................... 84 ...... 85

    3

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    2/83

    Programarea calculatoarelor Cibernetic, Statistic i Informatic Economic 1 , Cibernetic i Informatic Economic Statistica 1 2

    , Informatic Economic Informatic Economic iLimbi Moderne Aplicate. .

    . .

    :

    1 C. , 4-122 , , 4-123 4-124 4-125 4-126 , 4-127 main() 2-88 2-49 2-8

    , , . , , , , . .

    , . , , . .

    4

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    3/83

    N 1

    : . ,

    : , , ,

    .

    :

    , .

    . . . .

    , , 3, -2, 2003, 1.2, 3.141592653, -123.456, a, S, %, Informatica, CiBeR .

    , : a , 4 , &, ; .. - . backslash: \ . backslash : \\ , \ .

    ,

    : ArboreleLumii .

    : 5, -12, 65432, 3.14,123.456, 0.314E+1 ..

    , , . , .

    . () . , _ . .

    . . . , , . , . , , .

    . . : char,

    int, float, double. char , . ASCII,

    5

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    4/83

    . , char -128 127 . char .

    . , : char car; char rac, arc; ..

    =: car=; rac=i; arc=b; ..

    , char car; char . car=; , car , , .. 67 ASCII .

    int . int , , . , , , int

    , - -32768 32767 . , int .

    : int an=2003,luna; , an , 2003 , luna - .

    float , . () ,

    .. 7 . 4 . - 1.710 -38 1.710 +38 .

    double . 8 . , .. 15 . - 1.710 -308 1.710 +308 .

    , , ( ). ,

    - 9460800000000. : 9.460812,94.60811, 0.9460813 .. , , 10. , 3.140, 0.3141, 31.4-1, 314.0-2 3.14 ., , ( ) , .

    . . . : short ( ), long ( ),signed ( ), unsigned ( ). , int short int, long int, signed int,unsigned int, long signed int, long unsigned int.

    signed unsigned .

    , . ,

    6

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    5/83

    , . unsigned . ,

    ., char signed char . ,

    unsigned char 0 255 . , char 1 .

    , int signed int . unsigned int 0 65535 . , int ( ) 2 .

    long int, unsigned int double . long int unsigned long int int : long unsigned long . ( long unsigned unsigned long ) . int 2 , long 4 . int 4 , long 4 .

    long double . 10

    18 . - 3.4-4932 1.1+4932 ., . ,

    314 int , 45678 long , .. int . long , 314 . , , l L : 314l 314L . unsigned . u U unsigned . l L u U ( ).

    . . , , . . /* , */ , . / * .

    clrscr() . . void clrscr( void ); .

    getch() , Enter. ASCII . ASCII : 0, . .

    , getch() - .

    int getch( void ); .

    7

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    6/83

    getche( ) , Enter. ASCII . ASCII : 0, . .

    int getche( void ); .

    putch( e ) . . . [32;126] . , . , ,

    . , putch( 10 ) , putch( \n ) , . , .

    int putch( int c ); .

    getchar() ASCII ENTER. ENTER, . . , . ENTER.

    int getchar( void ); .

    putchar( e ) ASCII . , 1 .

    putchar( \n ) putchar( 10 ) .

    int putchar( int e ); .

    gets( s ) ASCII, . . char . ENTER NUL ( \0 ) , , .. \n \0 . , n n+1 . , , .. . EOF , 0.

    .

    8

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    7/83

    puts( s ) ASCII NUL ( \0 ) . , . , char . NUL , , , ..

    \0 \n. , .. NUL , 1 .

    .

    printf( c, p1, p2, p3, ) . . , c , . , c . escape, '\n, \t, \0 . , . p1, p2, p3 , , . c . % ( . 1 ). . p1, p2 , p3, . c .

    , , . .

    , . , , . ,

    . . , , .

    0 0 .

    ( ) 1 .

    .

    scanf( c, p1, p2, p3, ) . . , , . , . 1, 2, 3, - , . &

    .

    9

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    8/83

    . % ( . 1 ).

    . ,

    . - . .

    .

    fflush( stdin ) ( ).

    .

    exit( c ) . . , 0 , . .

    .

    sizeof . , sizeof( int ) , int , sizeof( d ) d .

    :

    1.1. , getch() , ASCII , putch() .

    #include #include void main(void){ char a;

    clrscr();a=getch();putch(a);getch();

    }

    1.2. , getch(), ASCII , printf() .

    #include

    #include void main(void)

    10

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    9/83

    { char a;clrscr();getch(); // Primul apelprintf("%d\n",getch()); // Al doilea apelgetch(); // Primul apela=getch(); // Al doilea apel

    printf("%d\n",a);getch(); // Primul apelprintf("%d\n",a=getch()); // Al doilea apelgetch();

    }

    1.3. , , .

    #include #include void main(void){ char c;

    clrscr();c=getchar();putchar(c-1);getch();

    }

    1.4. .

    #include #include #include void main(void){ char s[256];

    clrscr();gets(s);printf(irul are %d caractere,strlen(s));getch();

    }

    1.5. .

    #include #include void main(void){ int a,b,c;

    clrscr();scanf(%d %d %d,&a,&b,&c);

    printf(a=%d\tb=%d\tc=%d\nmedia=%.2f,a,b,c,(a+b+c)/3.0); //media cu 2 zecimale

    11

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    10/83

    getch();}

    1.6. * 123.456f ( #define ), float .

    #include #include #define a 123.456f void main(void){ clrscr();

    printf("*%f*\n",a);printf("*%2f*\n",a);printf("*%20f*\n",a);printf("*%-20f*\n",a);printf("*%020f*\n",a);printf("*%.2f*\n",a);printf("*%.10f*\n",a);printf("*%2.2f*\n",a);printf("*%2.10f*\n",a);printf("*%20.10f*\n",a);printf("*%-20.10f*\n",a);printf("*%020.10f*\n",a);getch();

    }

    :

    . .

    1.0. 1.1-1.6 .

    1.1. ( getche() ) ( putch() ), ( putch('\n') ), ( getch() ) - .

    , ASCII?

    1.2. SCII ( getchar() ) ( putchar() ), ( putchar(\n) ), ( getch() ) .

    , ,

    ASCII? putch( `\n` ) putchar( `\n` ) ?

    12

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    11/83

    1.3. ( gets() ), ( putchar() ) ( ), newline ( putchar(`\n`) ), ( getch() ) - .

    1.4. ( getchar() ) , ( printf() ) *, newline , -.

    1.5. ( getchar() ) , ( printf() ) %, newline , - .

    1.6. * Limbajul C++ : %s, %15s, %-15s, %10s, %15.10s,%-15.10s .

    1.7. ASCII ( getchar() ) ( printf() ) .

    1.8. , ASCII ( getch() ) ( printf() ) .

    1.9. 12345 , #define , 10-, 8- 16- .

    1.10. 123456789 , #define , 10-, 8- 16- .

    1.11. * 123( #define ) : %d, %2d,%10d, %-10d, %010d, %ld, %u, %lu .

    .

    1.12. * 123.456( #define )

    double . f, e, E, g, G, lf, le, lG, lE, lg . 1.6 . .

    1.13. * 123.456l( #define ) longdouble .

    Lf, Le, LE, Lg, LG . .

    13

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    12/83

    1.6 1.12 . .

    1.14. ( scanf() ) ( printf() ) ASCII .

    1.15. ( scanf() ) , , ( puts() ) , .

    1.16. ( gets() ) , ( printf() ) ,

    . , , Enter?

    1.17. ( scanf() ) , 4 ( printf() ) 10-,8- 16- .

    1.18. ( scanf() ) , 9 ( printf() ) 10-,8- 16- .

    1.19. ( scanf() ) ddmmyy( 6 ) 20yy/mm/dd . dd, mm, yy , , .

    1.20. ( scanf() ) ( printf() ) .

    1.21. sizeof , ( char, signed char,unsigned char, short, signed short, unsigned short, int, signed int,unsigned int, long int, long signed int, long unsigned int, float, double,long double ).

    :

    1.1. Borland C++ ?1.2. Borland C++ ?1.3. Borland C++ ?1.4. ?1.5. help ,

    clrscr() ?1.6. ( )?1.7. ( )?

    1.8. ?1.9. ?

    14

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    13/83

    1.10. Enter?1.11. Enter?1.12. getche() getchar() ?1.13. putch() putchar() ?1.14. ?1.15. ?

    1.16. ?1.17. ?1.18. Enter, ^z, ^c,

    F1, BS, Esc etc.?1.19. \n, \t, \a, ^z, ^c,

    EOF, NUL etc.?1.20. ,

    ASCII?1.21. main() ?1.22. void main(void) ?1.23. printf()

    % ?1.24. , ?1.25. clrscr() ?1.26. exit() ?1.27. ?1.28. ?1.29. ?1.30. ?1.31. : char, int, float,

    double, long double ?1.32. Borland C++

    ( Home, End, ^y Edit-Copy,Edit-Cut, Edit-Paste ).

    1.33. _01 .

    15

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    14/83

    N 2

    : , ,

    : , .

    :

    , , pow( x, y ), poly( x,n, c[] ), sin( x ) . .

    pow( x, y ) x y double pow( double x, double y );

    poly( x, n, c[] ) p=c n x n+c n-1 x n-1 ++c 2 x 2+c 1 x+c 0 double poly( double x, int n, double c[] );

    sin( x ) , double sin( double x );

    . , /180 , 3,14159265358979 .

    a 1 , a 2 , , a n (a 1 a 2 a n)1/n .

    - . - , . , ,

    .. , , . , .

    : char, short int enum int; , , . ,

    . .

    : long double, double, float, unsigned long, long, unsignedint, int.

    () , cast. , , (tip)operand . , (int)x x

    int .

    16

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    15/83

    : < - , -, >= - .

    : == - , != - .

    : ! - , && - , || - . : ! 0 ( false ) , , 1 (true ) , ; a&&b 1

    , b ; ||b 0 , b .

    , 0 ( false ) 1 ( true ). int .

    : ~ - 1, > - , & - , ^ - 2, | - . int .

    :

    2.1. .

    #include

    #include void main(void){ float a,b;

    clrscr();scanf(%f %f,&a,&b);printf(Numerele citite: %f\t%f\n,a,b);printf(Numerele ordonate: %f\t%f,

    a>b?b:a,a>b?a:b);getch();

    }

    2.2. , , 3.

    #include #include void main(void){ unsigned a,b,c;

    scanf(%u %u %u,&a,&b,&c);(a+b+c)%3==0 ? printf(Da) : printf(Nu);

    getch();

    }

    17

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    16/83

    2.3. !a&&b, !c||d, !e&&f||!f&&e .

    #include #include void main(void)

    { int a,b; float c,d; double e,f;clrscr();scanf(%d %d,&a,&b);printf(\na=%-d\tb=%-d\t!a&&b=%-d\n\n,

    a,b, !a&&b);scanf(%f %f,&c,&d);printf(\nc=%-f\td=%-f\t!c||d=%-d\n\n,

    c,d, !c||d);scanf(%lf %lf,&e,&f);printf(\ne=%-lf\tf=%-lf\t!e&&f||!f&&e=%-d,

    e,f, !e&&f||!f&&e);getch();

    }

    2.4. n=max(a,b,c) , d=max(a,b) , n=max(d,c) a, b, c . , . ?! .

    #include #include

    void main(void){ unsigned a=5,b=2,c=3,d,n;

    clrscr();printf(a=%-u\tb=%-u\tc=%-u\t

    max(a,b)=%-u\tmax(a,b,c)= %u,a,b,c,d=a>b?a:b,n=d>c?d:c);

    getch();}

    2.5 . >. x=1, u=4; x=2, u=8; x=3, u=5; x=2 16 ,u=2 14 ; x= -1, u= -1; x= -2, u= -2; x= -4, u= -4; x= -5, u= -5 . .

    #include #include void main(void){ long x,y; int u,w;

    clrscr();printf(Introdu x i u );scanf(%ld %d,&x,&u);

    w=u2=%-ld\n,x,x,y);

    18

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    17/83

    getch();}

    2.6 . s , s .

    #include #include void main(void){ int s;

    clrscr();scanf(%d,&s);printf(s=%-d\ts|1=%-d,s,s|1);getch();

    }

    :

    C . .

    2.0. 2.1-2.6 .

    2.1. float , y=3.5x 3-3.5x 2+3.5x-3.5 .

    2.2. int , =3 2+7+17

    . =1, 10, 100, 1000 . ,

    . , .

    2.3. double , a=x 19 +x 15 +x 9+x 5+1 x .

    pow( x, y ) . =1, 10, 100, 1000 . , . , ?

    2.4. c 0, c 1 , c 2 , c 3 , c 4 double q=c 4 x 4+c 3 x 3+c 2 x 2+c 1 x+c 0 , q x q .

    poly( x, n, c[] ) .

    2.5. () ().

    ( )?

    2.6. , jugre, , prjini ptrate stnjeni ptrai ( 1

    19

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    18/83

    jugr=576 prjini ptrate=5764.6415 .., 1 =10000 .. ) .

    2.7. .

    2.8. , , g, m, s .

    sin( x ) .

    2.9. n una int r una double 0 , r>n , 1 .

    2.10. w 2000 , 1000

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    19/83

    2.20. z=4 2+9-2000 , 0 .

    .

    :

    2.1. , , ; ?2.2. ?

    ?2.3. .2.4. .2.5. sizeof ?2.6. & ?2.7. ? : ?2.8.

    char ?2.9.

    ?2.10.

    ( float )?2.11.

    ( double )?2.12.

    ( long double )?2.13. : c, 3, 3.14, 3.14l, 3.14 ?2.14. ,

    ?2.15. pow( x, y ), poly( x, n,

    c[] ), cos( x ), sqrt( x ) ?

    2.16. : int, long,unsigned, long unsigned ?

    2.17. : float, double,long double ?

    2.18. char ?2.19. ( Pi

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    20/83

    2.27. int x=1; x=5, x=4, x=3, x=2; ?2.28. int n=1; m=2; t=3; z=4; t=n/m; z=n%m;

    t u z ?2.29. bs(), ceil(), floor() .

    help .2.30. ( (), [], ., ->, +

    (), - (), ++, --, (type), sizeof(), ~, * (), /, %,+ (), - (), , , ==, !=, & (),^, |, &&, ||, ?, :, =, =, +=, -=, *=, /=, %=, &=, ^=, |=, , ).

    2.31. _02 .

    22

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    21/83

    true falseexpr

    instruction1

    N 3

    :

    :

    :

    : { ; ; } . . .

    if . : . : if( expr ) instruction1; :

    , . true , .. 0 ,

    instruction1 , if . .

    if : if( expr ) instruction1; elseinstruction2; . , , instruction1 , instruction2 . , if . instruction1 instruction2 , . if :

    23

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    22/83

    true falseexpr

    instruction1

    if .

    for : for( e1;e2;e3 ) ; 1, 2, 3 : 1 - ; e2 - , ; e3 - . .

    . , . . : for( e1; e2; e3 );

    for : 1 , 2 . 2 0 , .. ,

    - . , .. 2 0( ) , for . , - , 3 , 2 .

    for :

    24

    false

    e1

    e2

    e3

    true

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    23/83

    while : while( e1 ) ; - while( e1 ) , 1 , . - , . , .

    :

    . 1 , 1 true .

    e1 false , .

    . : while( e1 );

    do-while : do while( e1 );

    , . :

    do-while : , .. , 1 -

    . 1 , . , .. 1=0 , , .

    . :do while( e1 );

    25

    false

    true

    e1

    truee1

    false

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    24/83

    continue continue; .

    break switch . break , , . break switch , switch .

    switch , .

    switch :

    switch( expresie ){ case c1: ir1; break;

    case c2: ir2; break;case cn: irn; break;default: ir; }

    1, 2, , n , expr switch , s1, s2,, sn s . switch : expr , 1, 2,

    , n . case , .. ., 3 , case c3 , .. s3 . break , s3 . break switch , .. , switch . 1, 2, , n , default ,

    .. s default . default . , 1, 2, , n , switch , switch . default switch , break s . break . , , . . break , switch. ,

    . , s127 1, 2

    7 expr , case c1: case c2: casec7: s127; break;

    26

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    25/83

    case default switch( switch ).

    goto . goto ; . ( ), ':' . , lab1: i++ ; lab1 - . goto lab1; lab1 , .. i ++;

    return . return; return expr; , .

    , - , , expr . expr

    . return , . return .

    :

    3.1. .

    unsigned dc(unsigned a, unsigned b){ unsigned c,d=1;

    if (a==0||b==0) return a>b?a:b;else for(c=2; c

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    26/83

    }

    3.3. , .

    #include

    #include void main(void){ int n;

    clrscr();printf("Introducei o cifr: ");while(3.14){ if (scanf("%d",&n)==1) break;

    clrscr();printf("\nN-ai introdus o cifr!\n");printf("Introducei o cifr: ");fflush(stdin); }

    printf("\n\nAi introdus numrul ");switch(n){ case 0: case 2: case 4: case 6:

    case 8: printf("par %u",n); break;default: printf(" %d",n); break;case 1: case 3: case 5: case 7:case 9: printf("impar %u",n); }

    getch();

    }

    3.4. , .

    #include #include void main(void){ int n[100],d=1,i=0,j;

    clrscr();

    printf("Introducei un ir numeric: ");while( scanf("%d",&n[i])==1 ) i++;

    for (j=--i; j>1; j--,i--){ if ( (n[i]-n[i-1])!=(n[i-1]-n[i-2]) ) d=0;}

    printf("\n\nirul introdus ");if(!d) printf("nu ");printf("formeaz o progresie aritmetic.");

    getch();}

    28

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    27/83

    }

    3.5. .

    #include

    #include void main(void){ double t,x[100];int i=0,j=0,k;

    clrscr();while(scanf(%lf,&x[i++])==1);i-=2;printf(\nAi introdus irul:\n);for( ; j

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    28/83

    3.1. float y=5x 2+3x-1 , x 0 y=3x-1 ,

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    29/83

    3.11. , .

    while ( ).

    3.12. ( printf() ) ( putch() ) ASCII.

    while .

    3.13. , : 1) m=(x 1+x 2+ x n)/n , 2) (x1*x2*xn)1/n , 3) (((x1-m) 2+(x 2-m) 2++(x n-m) 2 )/n) 1/2 .

    while if .

    3.14. , .. .

    70 . , abac a, ab, aba , bac, ac, c .

    3.15. [ 0;1 ] , =10 -10 .

    : x n+1 =0.5(x n+a/x n), n=0, 1, 2, ; x 0=1 . |x n+1 -x n |< .

    3.16. s , . ( ) ( ) s .

    do-while , double cast .

    3.17. long unsigned , .

    for . , 1 .

    3.18. , , , a, b, c , .

    .

    3.19. unsigned .

    3.20. [ 1;7 ] , ( 1 - , 2 - ,, 7 ).

    switch .

    31

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    30/83

    3.21. op1 op op2 , 1 2 -, - , (+, -, * / ) .

    switch .

    3.22. n , n , pow( x, n ) . n - int , x - long double .

    3.23. x s s int [ m; n ] 1 long double .

    #include .

    3.24. , , .

    3.25. , .

    :

    3.1. ?3.2. ?

    3.3. ? .3.4. if ? ,

    if.3.5. ?

    ?3.6. ?

    ?3.7. for ,

    ? for ?3.8. while ,

    ? while .3.9. do-while , ?

    do-while .3.10. for, while, do-while ?3.11. switch ?

    ?3.12. continue break ?3.13. case default ?3.14. ?3.15. : for(;;); for(;;) continue; for(;;)

    break ; ? .

    3.16. : while(3.14); while(0); while(-1) continue; while(0) continue; while(1) break ; ? .

    32

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    31/83

    3.17. : do { ; } while( 3.14 ); do{ continue; } while( -1 ); do { break; } while( 0 ); do { continue; } while( 0 );do { break; } while( 1 ) ; ? .

    3.18. char h; h=getch(); puts( );switch( h ){ default: puts();

    case 1: printf(%d\n,1);case 2: printf(%d\n,2);case 3: printf(%d\n,3);case 4: printf(%d\n,4);

    } ? .3.19. int x; do { clrscr(); puts( ! ) }

    while( !scanf(%d,&x) ); ? .

    3.20. float x,y,z; do { clrscr(); puts( ! ) }while( !(scanf(%f%f%f,&x,&y,&z)==3) ); ? .

    3.21. int a,b; printf( a b: ); for( ;scanf(%d%d,&a,&b)!=2; ) { clrscr(); printf( .!\n); printf( a b: ); } . ? .

    3.22. long double w; printf(\nw=); while( scanf(%Lf,&w)!=1 ) { clrscr(); printf(! .\n); printf(\nw=); } . ? .

    3.23. return ? .3.24. _03

    .

    33

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    32/83

    N 4

    : ( )

    : ( ) .

    :

    ( ) , . - . ( )

    , .

    tip *name, name - , , tip , .. , - . :int x ; int *p; : p ; x - int , - int , .. p

    int . , int * . int . ( ) int.

    char *, float *, double *, long *, int **, long double *** ..

    char, float, double, long, int *, long double **. : char *s[234]; unsigned *r[25][25];

    ..

    . , , , .. 2 . , near, far,huge , ,

    . far huge 2 , .. 4 , near , , , .. 2 .

    &: int x=10; int *p; p=&x; - , 10 , - int , , . :float w; float *y=&w; char *ps=Cibernetica; ps -

    char * , , Cibernetica , .. .

    void * ( ). ,

    34

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    33/83

    , , void *p . , -

    . void *, .

    *( , ). - , * - , . , int x=10; *p; p=&x ; int , , * , .. 10 . *=20 ; 20 ,

    , .. =20; , float r, *q; q=&r; *q=3.141593 , r 3.141593 .

    void * , .. , . float x=2.82; void *r; r=&x ; *r , . *(float *)r . *r+7.18. * (float*)r+7.18;

    . , int

    x=1, *px=&x; double z=3.14, *pz=&z; print(%p%d%p%lf,px,*px,pz,*pz); z ,. .

    . : , , , , , .

    ( ++ ) ( -- ) . ++ ( -- ), , ( ) , , . , int *p; ++, ++, 2 , int 2 . , double *w; w++, ++w, w 8 , double 8 .

    ( ) ( ) . - . +n ( -n ) ( ) n*r , r - , , ., char *c; float *f; long doble *w ; unsigned n=5;

    c+n, f+n, w+n; , f, w 5 *1=5,

    5*4=20 5*10=50 , , char

    35

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    34/83

    1 , float - 4 long double - 10 , .

    , , , . - tab[i] tab ( .. &tab[i] ), q -

    tab[j] tab ( .. q &tab[j] ). q . ,

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    35/83

    clrscr();px=x;r=*px;for(i=0;i

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    36/83

    #include #include #include void main(){ char sir[256]="Asem CSIE",c,i=-1;

    clrscr();c=*sir;for( ; ++i

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    37/83

    for(i=0;i

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    38/83

    'u','v','w','x','y' };int i,j;clrscr();

    for(i=0;i

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    39/83

    4.7. p x, y( p=x 1 y 1+x 2 y 2++x n y n ), .

    4.8. y=( y 1 ,y 2 ,,y n ), A m x n a ij , i=1, 2, ,m, j=1, 2, , n x=( x 1 ,x 2 ,,x m ) ( y i=a i1 x 1+a i2 x 2++a im x m , i=1, 2,3, , n ).

    4.9. C m x n c ij, i=1, 2, , m, j=1, 2, , n, A m x p a ik , i=1, 2, , m, k=1, 2, , p B p x n bkj , k=1, 2, , p, j=1, 2, , n (c ij=a i1 b1j +a i2 b2j ++a ip bpj , i=1, 2, , m, j=1, 2, , n ).

    4.10. ( ! ), TRACTOR ( RAC, TOR,

    ROTOR . . ). , .

    :

    4.1. ?4.2. ?4.3. ?4.4. & ?4.5.

    * ?4.6. char tab[256]; int vec[33]; float mat[4][3]; double cub[2]

    [3][4]; tb, vec, mat, cub, mat[2], cub[1],cub[2][3] ?

    4.7. hear, far, huge ? , ?

    4.8. , NULL ?

    4.9. : int near *px; float far *py;double huge *pz; char *pa; long huge *pd; long double *pw; ?

    4.10. char a=a,*pa; int x =10, *px; float y=2.8, *py; doublez =12345.54321, *pz; long double w =123456789.987654321, *pw; pa =&a;px=&x; py=&y; pz=&z; pw=&w; printf(%c\t%d\t%f\t%lt\t%Lf\n, *pa,*px,*py,*pz,*pw); ?

    4.11. char a, *pa=&a; int x, *px=&x; float q, *pq=&q; doubler, *pr=&r; long doable w , *pw=&w; scanf(%c%d%f%lf%Lf,pa,px,pq,pr,pw); scanf() printf(%c\t%d\t%f\t%lf\t%Lf\n,*pa,*px,*pq,*pr,*pw); ?

    4.12. int x=2003, *p=&x, **q=&p, ***w=&q; printf(%d%d%d%d,x,*p,**q,***w); ?

    4.13. char s[22]= 0,1,2,3,4,5 , *ps=s; int x[22]={0,1,2,3,4,5}, *px=x; float y[22]={0,1,2,3,4,5}, *py=y; double

    41

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    40/83

    z[22]={0,1,2,3,4,5}, *pz=z; long double w[22]={0,1,2,3,4,5}, *pw=w; printf(%c%d%f%lf%Lf,*(ps+1),*(px+2),*(py+3),*(pz+4),*(pw+5)); ?

    4.14. short i[22]={0,1,2,3,4,5}, *pi=i; printf(%d%d%d%d%d%d,*pi,*pi++,*pi++,*pi++,*pi++,*pi++); ?

    4.15. int i[22]={0,1,2,3,4,5}, *pi=i; printf(%d%d%d%d%d%d,*pi,*++pi,*++pi,*pi++,*pi++,*pi++); ?

    4.16. float i[22]={0,1,2,3,4,5},*pi=i+5; printf(%f%f%f%f%f%f,*pi,*pi--,*pi--,*pi--,*pi--,*pi--); ?

    4.17. double i[22]={0,1,2,3,4,5), *pi=i+5; printf(%d%d%d%d%d%d,*pi,*--pi,*--pi,*--pi,*--pi,*--pi); ?

    4.18. _04 .

    42

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    41/83

    N 5

    :

    : .

    :

    , text , 100 . 30 , .

    , . , 4

    100, , 400.

    . , str .

    strcmp() int strcmp( const char *s1, constchar *s2 ); 1 2 , s1 s2, . , c1>c2 , 0 , 1=2 , , c1c2 , 0 , 1=2 , , c1c2, 0 , 1=2 , , c1c2 , 0 , 1=2 , , c1

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    42/83

    s . NUL , , .

    strcpy() char *strcpy( char *d, const char *s ); ,

    s , d . \0 . d .

    strncpy() char *strnpy( char *d, const char *s,unsigned n ); n , , s , d . d .

    strcat() char *strcat( char *d, const char *s ); , d s : , s , , ,

    d . \0 . d .

    strncat() char *strncat( char *d, const char *s,unsigned n ); ,

    d , n , s : n , , s , , ,

    d . d .

    strchr() char *strchr( const char *s, int c ); c , s .

    c NULL .

    strstr() char *strstr( const char *s1, const char*s2 ); c2 ,

    s2 , c1 , s1 .

    s2 s1 NULL .

    malloc() void *malloc( unsigned n ); . heap n void ,

    . , . ( calloc(), farmalloc(), farcalloc() ).

    44

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    43/83

    free() void free( void *p ); . heap ,

    p . ( void farfree( void far *p ); ).

    :

    5.1. .

    char *bw(char *c1, char *c2, char *c3){ char *p;

    p=( strcmp(c1,c2)>0 )?c1:c2;return ( strcmp(p,c3)>0 )?p:c3;

    }

    5.2. . , f:\bc\mydir\ex5_1.c .

    #include #include #include #include f:\bc\mydir\ex5_1.cvoid main(void){ char c1[30], c2[30], c3[30], c4[30], *q;

    clrscr();

    printf(Introdu un text din patru cuvinte: );scanf(%s %s %s %s,c1,c2,c3,c4);printf(\nAi introdus textul:\n\n);printf(%s %s %s %s\n\n,c1,c2,c3,c4);q=bw(c1,c2,c3);q=( strcmp(q,c4)>0 )?q:c4;printf(Cel mai mare cuvnt este: );puts(q);getch();

    }

    5.3. .

    char *sw(char *w1, char *w2, char *w3){ char *p;

    p=( strlen(w1)

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    44/83

    #include #include #include #include f:\bc\mydir\ex5_3.cvoid main(void)

    { char z1[30], z2[30], z3[30], z4[30], z5[30], *w;clrscr();printf(Introdu un text din cinci cuvinte: );scanf(%s %s %s %s %s,z1,z2,z3,z4,z5);printf(\nAi introdus textul:\n\n);printf(%s %s %s %s %s\n\n,z1,z2,z3,z4,z5);w=sw(z1,z2,z3);w=sw(w,z4,z5);printf(Cel mai scurt cuvnt este: );puts(w);getch();

    }

    5.5. heap . , , .

    char *wh(char *w){ char *p;

    p=(char *)malloc( strlen(w)+1 );if( p ) strcpy(p,w);

    return p;}

    5.6. .

    void sd(char *wp[], unsigned n){ char *t, i=0,j;

    while( i

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    45/83

    while( j

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    46/83

    for( ; i2 ) d+=( (a%4==0)&&(a%100)||(a%400==0) );return d;

    }

    5.11. ( ) .

    void daz(unsigned an, unsigned zi, int *d, char l[]){ static char *dl[]=

    {, Ianuarie, Februarie, Martie,Aprilie, Mai, Iunie,Iulie, August, Septembrie,Octombrie, Noiembrie, Decembrie};

    static unsigned nz[]={0, 31, 28, 31, 30, 31, 30,

    31, 31, 30, 31, 30, 31};unsigned nl=0,s=0;nz[2]+=( (an%4==0)&&(an%100)||(an%400==0) );while( s

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    47/83

    365+bi-nd1; }r=nd1nd2%7; return eliz[r]; }

    if( yyyy>1999 ){ d2=dd, strcpy(m2,luna), a2=yyyy,

    d1=16, strcpy(m1,"Noiembrie") ,a1=1999;

    nd1=nz(d1,m1,a1); nd2=nz(d2,m2,a2);if( a2-a1==1 ){ b=(a1%4==0)&&(a1%100)||(a1%400==0);

    nd1nd2=nd2+365+b-nd1; }else { for(b=0,i=a1;ind2) ){ d2=dd; strcpy(m2,luna); a2=yyyy;

    d1=16, strcpy(m1,"Noiembrie") ,a1=1999;nd1=nz(d1,m1,a1); nd2=nz(d2,m2,a2);printf("nd1=%u nd2=%u\n",nd1,nd2); getch();nd1nd2=nd2-nd1; r=nd1nd2%7; return zile[r]; }

    else { nd1nd2=nd2-nd1; r=nd1nd2%7;return eliz[r]; }

    }

    5.13. dd luna yyyy . dd ,luna yyyy - . , . 5.10 5.12 , f:\bc\mydir\ex5_10.c f:\bc\mydir\ex5_12.c , .

    #include #include #include

    unsigned zl[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    char *dl[]={ "", "Ianuarie", "Februarie", "Martie",

    "Aprilie", "Mai", "Iunie","Iulie", "August", "Septembrie","Octombrie", "Noiembrie", "Decembrie" };

    char *zile[]=

    { "Mari", "Miercuri", "Joi", "Vineri","Smbt", "Duminic", "Luni" };

    49

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    48/83

    char *eliz[]={ "Mari", "Luni", "Duminic", "Smbt",

    "Vineri", "Joi", "Miercuri" };

    #include "f:\bc\mydir\ex5_10.c"#include "f:\bc\mydir\ex5_12.c"

    void main(void){ unsigned d,y; char luna[30], *p;

    clrscr();printf("Introdu o dat calendaristic

    dd luna yyyy: ");scanf("%2d %s %4d",&d,luna,&y);printf("\nAti introdus data: %2d %s %4d\n\n",

    d,luna,y);p=ziua(d,luna,y);printf("%s",p);getch();

    }

    :

    . .

    5.0. 5.1-5.13 .

    5.1. ( ).

    strcmp() .

    5.2. ( ) .

    strlen() .

    5.3. ( ) . strcmp(), strcpy() .

    5.4. ( ).

    strlen(), strcpy() .

    5.5. ( ) _ .

    stricmp(), strcpy() .

    5.6.

    ( ) . strlen(), strcpy() .

    50

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    49/83

    5.7. , EOF , ( ) , heap , .

    5.5 .

    5.8. , EOF , ( ) , heap , .

    5.5 .

    5.9. , EOF heap , ( ) .

    5.6 .

    5.10. , EOF heap , ( ) .

    5.7 .

    5.11. ddmmyy , dd , mm - yy -

    ; , , ddluna yyyy , luna - yyyy ( 4 ) -

    . 5.8 .

    5.12. dd luna yyyy , dd- , luna - yyyy ( 4 ) - ; , , dd/mm/yy , mm , yy -

    . 5.9 .

    5.13. , , , , .

    5.11 .

    5.14. , ,.

    5.15. , .

    5.16. ,

    , .

    51

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    50/83

    :

    5.1. : strcmp( asem, ASEM ), stricmp(ASEM, asem ), strncmp( Limbajul C, Limbajul C++, 10 ), strncmp(Limbajul C++, Limbajul C, 12 ), strncmp( Limbajul C++, Limbajul C,14 ), strnicmp( ABRACADABRA, arbadacarba, 1 ) ? .

    5.2. : strlen( ASEM ), strlen( asem0 ), strlen(asem\0 ), strlen( ASEM\n ), strlen( ASEM\N ), strlen( ), strlen( \0), strlen( 0 ), strlen( Cibernetica\t ) ? .

    5.3. : strcat( Limbajul C, ++ ), strncat(Cibernetic, , Informatic Economic, Statistic, Previziune Economic,21 ) ? .

    5.4. char s[]=abracadabra, *p; p=strchr( s, a ); printf( %c\t%d\t%p\n, *p, p+1, p+6 ); ? .

    5.5. char b[]=Cibernetica\n, *r, a=\n; r=strchr( b, a ); printf( %c\n, *r ); ? .

    5.6. puts( strstr( Contabilitate financiara, abil ) );?

    5.7. char *s=Informatica, *p=Cibernetica,*q=Statistica, *r=Economica; strcpy( s, p ); strcpy( p, q ); strcy( q, r );strcpy( r, s ); puts( s ); ? .

    5.8. char *p,*q,*r; puts( strncpy( p, LimbajulC++, 10 ) ); puts( strncpy( q, Limbajul C++, 12 ) ); puts( strncpy( r,Limbajul C++, 14 ) ); ? .

    5.9. int *x; float *y; double *z; long double *w; x=(int

    *)malloc( 5*sizeof( int ) ); y=(float *)malloc( 5*sizeof( float ) ); z=(double*)malloc( 5*sizeof( double ) ); w=(long double *)malloc( 5*sizeof( double ) );w=(long double *)malloc( 5*sizeof( long double ) ); malloc() x, y,z, w ? .

    5.10. malloc() calloc() ? (int *)malloc( 5*sizeof( int ) ); (int *)calloc( 5*sizeof( int ) ); ?.

    5.11. char *s=Costel, Vicu Andrei ,*q=Vicu; puts( strstr( s, q ) ); ? .

    5.12. _05 .

    52

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    51/83

    N 6

    : ,

    : , ( , , , ); typedef .

    :

    . , , , .

    . .

    . . ,, , .

    :

    struct name { } name1, name2, namen;

    name , name1, nam2, , namen , .. name . name . name1, name2, ,namen . name .

    , .. name , , .. name1, name2, ,namen , , . , ,

    .

    name ( , ) :

    struct name name_of_structure;

    :

    1) struct punct { int x; int y; } a, b, c, *w;

    punct a, b, c

    punct , .. int , w punct .

    53

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    52/83

    2) punct ., struct punct d, e={ 10, 20 }, *q, f[11]; d, e punct , ( , e ); q punct , f punct .

    1) struct dosar{

    char nume[25];char prenume[25];struct data_calenraristica

    { int zi;char luna[11];int an;

    } data_nasterii, data_angajarii;} angajat, secie[100];

    m.n p->n , m - , n - , , p - . , 1), a.x x a punct , w->y y punct , w.

    , ,

    . , 1), 2+2=4 , .. 2 , 2 .

    . .

    , . , struct union .

    , :

    union name { } name1, name2, , namen;

    :

    union aria { int x; // 2 octeifloat r; // 4 octei

    double w; // 8 octeichar t[5]; // 5*1=5 octei

    } f1, f2, f3[6], *z;

    54

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    53/83

    f1, f2 aria , f3 , 6 , aria ,

    z , aria .

    , , , ,

    . , 8 , w double 8 .

    , .

    , , . . .

    :

    enum name { name0, name1, , namen } v1, v2, , vm;

    name - , nam1, name2, ,namen - , , : name0 0 , name2 1 , , namen n . v1, v2, , vm - name , .. .

    int . , , name0, name1, , namen 0, 1, , n .

    . , namei=ci namei , namei ci . ci

    . , , 1. , .. name0 , 0.

    :

    1) enum luna { ileg, ian, feb, mar, apr, mai, iun, iul, aug, sep, oct, nov,dec } m1, m2, m3[12], *w;

    2) enum mon { ian=1, feb, mar, apr, mai, iun, iul, aug, sep, oct, nov,dec };

    3) enum boolean { false, true };

    55

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    54/83

    enum boolean bisect;

    4) enum { luni=1, marti, miercuri, joi, vineri, simbata, duminica } zi;

    ( ) .

    , .

    :

    typedef old_tip_name new_tip_name;

    :

    1) typedef int INTEGER;INTEGER x,y;

    2) typedef struct { double real; double imag; } COMPLEX;COMPLEX w, tz[11];

    3) typedef struct { int x; int y; } POINT;POINT a,b;

    1) typedef union { double raza; double tp; double ld[2]; double lt[3]; }figura;

    figura cerc, patrat, triunghi;

    . .

    . . . , -

    .

    :

    struct name { pole1; pole2; ; polen; } n1, n2, , nm;

    name - , n1, n2,, nm - , .. , pole1, pole2, , polen - .

    :

    tip imea_polea dlina_polea;

    56

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    55/83

    tip - , imea_polea - , dlina_polea - , . , , . 0, . , .

    , . unsigned, int, signed, char, usignedchar .

    .

    :

    struct { unsigned a:2;int b:2;unsigned :3;unsigned c:2;unsigned :0;int d:5;unsigned e:5; } x,y;

    2 x, y . , .. . x 2 : 0 1 a , 2 , .. 2 3 , b , 3 , .. 4, 5, 6 ,

    , . , 7, 8 c . 0 , , d , , . , d 0, 1, 2 , 3 , 4 . , , e 5, 6, 7, 8, 9 .

    , x.a=1; a 1 , .. 0 1 , 1 0 ., x.b=-1; b -1 , .. 2 3 1 , .. -1

    - 11 .

    . &.

    .

    :

    57

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    56/83

    6.1. . , COMPLEX . COMPLEX : typedef struct { double x; double y }COMPLEX; double , .

    z=x+iy argz :

    0 , x 0 y=0 ; /2 , x=0 y 0 ; , x0 ;arctg( y/x )+ , x0 yx >= 0) && (w->y == 0) ) return 0.0;if( (w->x == 0) && (w->y >=0) ) return PI/2;if( (w->x < 0) && (w->y == 0) ) return PI;if( (w->x == 0) && (w->y < 0) ) return 3*PI/2;a=atan( w->y / w->x );if( (w->x < 0) && (w->y != 0) ) return a+PI;if( (w->x > 0) && (w->y < 0) ) return a+2*PI;return a;

    }

    6.2. . darg() 6.1 , f:\bc\mydir\ex6_1.c .

    #include #include #include #define PI 3.14159265358979typedef struct { double x; double y; } COMPLEX;#include f:\bc\mydir\ex6_1.c

    void main(void){ COMPLEX z1,z2;double argz1, argz2;clrscr();printf(Introducei 2 numere complexe: );scanf(%lf %lf %lf %lf,

    &z1.x,&z1.y,&z2.x,&z2.y);argz1=darg(&z1); argz2=darg(&z2);printf(\n\nAi introdus numerele

    complexe:\n\n);printf(z1=(%-.2lf)+i(%-.2lf)\n

    z2=(%-.2lf+i(%-.2lf)\n\n,z1.x,z1.y,z2.x,z2.y);

    58

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    57/83

    printf(argz1=%-lf\nargz2=%-lf\n,argz1,argz2);printf(\nNumerele ordonate n ordinea creterii

    argumentelor:\n\n);(argz1

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    58/83

    printf(r(%2d)=(%-.2lf)+i(%-.2lf)\n,m, mod*cos(arg), mod*sin(arg) ); }

    getch();}

    6.4. . , RATIONAL , . RATIONAL :typedef struct { long unsigned m; long unsigned n; } RATIONAL; RATIONAL * ,

    . .

    RATIONAL *simplifica( RATIONAL *f){ static RATIONAL s;

    long unsigned k,h, cmmdc=1;/* h este minimul dintre numitorul i

    numrtorul fraciei f */h=(f->m)n)?(f->m):(f->n);/* cmmdc este cel mai mare divizor comun

    pentru numrtor i numitor */for(k=1; km) % k == 0 && (f->n) % k == 0 )cmmdc=k;

    s.m=(f->m)/cmmdc; s.n=(f->n)/cmmdc;return &s;

    }

    6.5. , , , . RATIONAL simplifica() 6.4 , f:\bc\mydir\ex6_4.c .

    #include #include typedef struct { long unsigned m; long unsigned n; }

    RATIONAL;#include "f:\bc\mydir\ex6_4.c"void main(void){ RATIONAL *p, frac;

    clrscr();printf("Introducei o fracie raional:\n\n");scanf("%lu %lu", &frac.m, &frac.n);printf("\n\nAi introdus fracia:\n\n");printf("%lu/%lu\n\n", frac.m, frac.n);p=simplifica( &frac );printf("Fracia simplificat este:\n\n");printf("%lu/%lu",p->m,p->n);

    getch();}

    60

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    59/83

    6.6. : , , , , . , , . :

    - a 3 , a - ; - 4/3 r 3 , r - ; - 1/3 r 2 h , h - , r -

    ; - r 2 h , h - , r -

    ; - a b c , a, b, c - ; - 1/3 a b h , h - , a, b -

    , .

    #include #include #include #define PI 3.14159265358979void main(void){ union { double r;

    double a[2];double b[3]; } c;

    int v; double volum; clrscr();printf(Alegei o alternativ:\n\n);printf(1 cub\n

    2 sfer\n3 con\n);

    printf(4 cilinrdu\n5 paralelepiped\n6 piramid\n\n);

    scanf(%d,&v); printf(\n\n);switch(v) { default:printf(Ai ales alternativa de

    ieire); getch(); exit(1);case 1: printf (Introducei lungimea

    laturii cubului: );scanf(%lf, &c.r);volum=c.r*c.r*c.r;printf(\n\nVolumul cubului culatura a=%-.2lf este ); break;

    case 2: printf(Introducei lungimea razeisferei: );scanf(%lf, &c.r);volum=4.0/3.0*PI*c.r*c.r*c.r;printf(\n\nVolumul sferei cu razar=%-.2lf este ); break;

    case 3: printf(Introducei lungimea razeicircumferinei din baza conului);

    61

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    60/83

    printf( i nlimea conului: );scanf(%lf%lf,&c.a[0],&c.a[1]);volum=1.0/3.0*PI*c.a[0]*c.a[0]*c.a[1];printf(\n\nVolumul conului cu razabazei);printf( r=%-.2lf i nlimea h=%-

    .2lf este ); break;case 4: printf(Introducei lungimea razei

    circumferinei din baza cilindrului);printf( i nlimea cilindrului: );scanf(%lf%lf,&c.a[0],&c.a[1]);volum=PI*c.a[0]*c.a[0]*c.a[1];printf(\n\nVolumul cilindrului curaza );printf(bazei r=%-.2lf i nlimeah=%-.2lf este ); break;

    case 5: printf(Introducei lungimilelaturilor paralelipipedului: );scanf(%lf%lf%lf,&c.b[0],&c.b[1],&c.b[2]);volum=c.b[0]*c.b[1]*c.b[2];printf(\n\nVolumul papalelipipeduluicu laturile );printf(a=%-.2lf, b=%-.2lf ic=%-.2lf este ); break;

    case 6: printf(Introducei lungimilelaturilor dreptunghiului );

    printf(din baza piramidei );printf(si inaltimea piramidei: );scanf(%lf%lf%lf,&c.b[0],&c.b[1],&c.b[2]);volum=1.0/3.0*c.b[0]*c.b[1]*c.b[2];printf(\n\nVolumul piramidei culaturile dreptunghiului );printf(din baz a=%-.2lf, b=%-.2lf i nlimea h=%-.2lf este );

    }printf(%-.2lf\n\n,volum);getch();

    }

    6.7. , . . : =1, =2, =3, =4.

    #include #include

    void main(void){ unsigned nl;

    62

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    61/83

    enum { Ian=1, Feb, Mar, Apr, Mai, Iun,Iul, Aug, Sep, Oct, Nov, Dec } dl;

    enum { Primvara=1, Vara, Toamna, Iarna } da;while(1){ clrscr();

    printf(Introducei numrul unei luni

    calendaristice: );if( scanf(%u, &dl)==1 )

    if( dl>0 && dl

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    62/83

    6.0. 6.1-6.8 .

    6.1. ( ,, , , , , , , , ,

    ).

    6.2. z n .

    6.3. n .

    6.4. z 2+b z+c=0 , a, b, c, z - .

    6.5.

    ( , , , , , , , ).

    6.6. .

    6.7. , : , , , ( ( x, y ) ! ).

    6.8. , 7 .

    6.9. , :, , , .

    union !

    6.10. ( , , , , , ,

    ).

    6.11. An A.

    6.12. det(A) - A.6.13. .

    6.14. A x=b A.

    6.15. , .

    enum !

    :

    64

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    63/83

    6.1. ? ?6.2. ?

    ?6.3. ?6.4. ?6.5. ?6.6. ?6.7. ?6.8. ?

    ?6.9. ?6.10. ?6.11. ?6.12. ?6.13. ?6.14. ?6.15. ?6.16. ?6.17. ?6.18. ?6.19. ?6.20. ?6.21. ?6.22.

    ?6.23. ?6.24. ?6.25. ?6.26. ?6.27.

    ?6.28.

    ?6.29.

    ?6.30.

    ?6.31. ?6.32. _06

    .

    65

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    64/83

    N 7

    : main()

    : main()

    :

    ( ++ ) , ... main() tip main( int argc, char*argv[] ) . argc ,

    1 , argv[] , . . argv[0] , ( .exe ). argv[1] , , argv[2]

    , .. , main() .

    MS DOS , , ,

    , , Enter .

    Borland C++ , Run-Arguments . Program Arguments , , , Enter OK . .

    :

    7.1. main() .

    #include #include void main(int argc, char *argv[]){ int i=0;

    clrscr();for( ; i++

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    65/83

    7.2. . main() .

    #include

    #include #include #include void main(int a, char *b[]){ char *dl[]=

    {"","Ianuarie", "Februarie", "Martie","Aprilie", "Mai", "Iunie","Iulie", "August", "Septembrie","Octombrie", "Noiembrie", "Decembrie"};

    int i,bi,an,nz[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    clrscr(); an=atoi(b[2]);bi=(an%4==0)&&(an%100)||(an%400==0);if( bi ) nz[2]+=1;for(i=1; i0 ) printf("\n\nargv[1]: %s\n",w[1]);else printf("\n\nargv[2]: %s\n",w[2]);

    getch(); }

    double c(int a, char **b){ double k; int m,n; clrscr();

    printf("Introduceti 2 numere: ");

    scanf("%d %d",&m,&n);if( m==0||n==0 ) main(a,b);

    67

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    66/83

    k=1.0/(double)m + 1.0/(double)n;return k; }

    7.4. main() . main() . ,

    - .

    #include #include #include void main(int a, char *b[]){ char *s; clrscr();

    printf("Limbajul de programare ? ");gets(s);if( strcmp(s,b[1]) )

    { printf("Greit ! Apsai o tast!\n");

    getch(); main(a,b); }printf("Corect ! Ai ghicit !

    Apsai o tast !\n");getch(); exit(1);

    }

    :

    . .

    7.0. 7.1-7.4 .

    7.1. . main() .

    7.2. main() : ( %s ) , ( % ).

    7.3. main() , argc .

    7.4. mm/dd/20yy , MS DOS dd month yy . dd , month , mm - , yy , .

    :

    7.0. main() ?

    68

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    67/83

    7.1. ( ) main() MS DOS ?

    7.2. main() Borland C++ ?7.3. main()

    ?7.4. main() ?7.5.

    main() , ?7.6. main()

    , ?7.7. main() ,

    argv[0] ?7.8.

    main() ?7.9. Monday, Tuesday, Thursday

    main( int a, char *v[] ){ char *b=Monday, *c=Tuesday, *d=Thursday;strcpy( v[1], d ); strcpy( v[a], b );printf(%d\t%s\t%s\t%s\n,a,v[1],v[2],v[3]);

    }

    ?

    7.10. _07 .

    69

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    68/83

    N 8

    :

    : .

    :

    . , . , ( ), ., fact( n ) . n 0 : fact( n )=1 , n=0 , fact( n )=n fact( n-1 ) , n>0.

    , . fact( n ) , fact( n )=1 , n=0 , , , .

    fact( n ) :

    double fact( int n ){ if (n==0) return 1.0;

    else return n*fact(n-1); }

    sscanf( p, c, p1, p2, ) scanf() . , p . c, p1, p2, scanf() . , - char . , ASCII . sscanf() , scanf() , . sscanf() , scanf() , , .

    , , gets() . , .

    :

    8.1. n [ 0;170 ] n! ( n ) , fact(n).

    #include

    70

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    69/83

    #include #define MAX 170void main(void){ double fact(int n);

    int n; char t[255];clrscr();

    for ( ; ; ){ printf(n=? );

    if( gets(t)>0 && sscanf(t,%d,&n)==1 &&n>=0 && n

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    70/83

    void main(void){ unsigned m=1,n=10;

    clrscr();printf(%-u\t%-u\tSuma=%-u,m,n,Suma(m,n));getch();

    }

    8.4. . .

    #include #include int x[4]={ 23,-34,43,-3 };void main(void){ int Mic(int );

    int n=3;clrscr();printf(Cel mai mic numr este %d, Mic(n));getch();

    }int Mic(int n){ if( n==0 ) return x[n];

    else return x[n]

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    71/83

    10, 11, 12, 5,9, 8, 7, 6 };

    void Tipar(int i, int j, int n, int m){ if( i>m||j>n) return;

    else { int k;

    for(k=j; ki; k--)printf("%d\t",A[k][j]);

    i++; j++; n--; m--;Tipar(i,j,n,m); }

    }

    void main(void){ clrscr();

    Tipar(0,0,2,3);getch();

    }

    :

    . .

    8.0. 8.1-8.6.

    8.1. A(n,k) n k, 1 k n 170. A(n,k) :A(n,k)=n!/(n-k)!

    .

    8.2. C(n,m) n m, 1 m n 170. C(n,m) :C(n,m)=n m=1 C(n,m)=C(n,m-1)/(m (n-m)) m=2, 3, , n. , .

    8.3. cmmdc(m,n) m n.

    8.4. , cmmdc(m,n), :cmmdc(m,n)=m, n=0 m 0, cmmdc(m,n)=n, m=0 n 0, cmmdc(m,n)=cmmdc(n,m%n), m>n>0. m=n=0 cmmdc(m,n) .

    73

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    72/83

    8.5. cmmmc(m,n) m n.

    8.6. cmmmc(m,n)=m n/cmmdc(m,n) ( 8.3 ).

    8.7. f(n), n 0 : f(n)=0, n=0, f(n)=1, n=1,f(n)=f(n-1)+f(n-2), n=2, 3, .

    8.8. a(m,n), m 0, n 0 : a(m,n)=n+1, m=0,a(m,n)=a(m-1,a(m,n-1)), m=1, 2, 3, , n=1, 2, 3, .

    8.9. ( abcd dcba

    ).8.10. f(abcd)=strcat( f( bcd ), a ).

    8.11. m, n [ min(m,n]; max(m,n) ].

    8.12. !

    8.13. .

    8.14. .

    8.15. . !

    . , , , , n

    . . . , .

    .

    :

    8.0. ?

    74

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    73/83

    8.1. ?

    8.2. , ?

    8.3. , ?

    .8.4. _08

    .

    75

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    74/83

    N 9

    :

    :

    :

    (, , , ..). . , . ,

    , . : ,

    ; , ,

    , . , , , .

    (bubblesort). . , . , , .. . . , .

    9.1, 9.2.

    Shell (shellsort; ). , 1, . , . .

    . , .

    Shell , .

    . . , .

    Shell 9.3.

    76

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    75/83

    I (quicksort; ). , , , , , , . . .

    . , . .

    , . , . I (quicksort). 9.4.

    II (quicksortinf; ). , . , . , . , , . . ,

    . . II (quicksortinf). 9.5.

    :

    9.0. , . , , . EOF . . f_9_00.c .

    // Exemplul 9_0. Functia citeste un textint ct(char w[], char *p[]) { // w[] - Textul, cuvintele sunt separate cu \0// p[] - Pointerii spre cuvinteint i=0; // Numrul de cuvinteint j=0; // Indice pentru cuvintechar c;c=getchar();while( c!=EOF ) {

    while( c'Z' && c'z' ) { c=getchar(); if( c==EOF ) break; }

    77

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    76/83

    if( c==EOF ) break;p[i++]=w+j;while( c>='A' && c='a' && c

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    77/83

    i=0; // Numrul de cuvinte j=0; // Indice pentru cuvinteclrscr();i=ct(w,p); // Citete textulclrscr();printf("Sortare prin metoda bulelor\n\n");

    printf("Textul introdus:\n\n");for(j=0; j 0; j=j-inc) { t=p[j]; p[j]=p[j+inc];p[j+inc]=t; ++z; } } }return z; }void main(void) { char w[(lc+1)*nc]; // Textul, cuvintele sunt separate cu \0char *p[nc]; // Pointerii spre cuvintechar *t;int c,i,j,k,q,z;clrscr();i=ct(w,p); // Citete textul

    clrscr();printf("Sortare prin metoda Shell\n\n");

    79

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    78/83

    printf("Textul introdus:\n\n");for(j=0; j

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    79/83

    printf("\nTextul sortat:\n\n");for(j=0; j

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    80/83

    :

    . .

    9.0. 9.1-9.5 .

    9.1. , , , , . , , . , , 1

    .

    . .

    9.2. 9.1. .

    9.3.

    Shell. .

    9.4. I. .

    9.5. II. .

    9.6. : , Shell, I, II. . .

    9.7. quicksort 9.4 , ,

    . ( a, b, c, a

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    81/83

    9.8. quicksortinf 9.5 , .

    :

    9.1. ?

    9.2. .9.3. Shell .9.4. I .9.5. II .9.6. ?9.7. 9.1-9.5?9.8. 9.1-9.5?9.9. , Shell

    2?9.10. , ,

    , ?

    9.11. I II, ? 9.4 9.5 , .

    9.12. _09 .

    83

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    82/83

    1

    ( printf() ),

    , ( scanf() ),

    .

    : %[flags][width][.prec][dim]type .

    flag

    - .0

    0, .+ ( + - ) . ( + )

    .# 0 0x

    0X . g, G, f, e, E .

    width .

    prec

    -

    ; - ; - .

    dim

    F far.N near.h ( d,i,o,u,x,X ) short int.l ( d,i,o,u,x,X) long int.l ( f,e,E,g,G ) double.

    L ( f,e,E,g,G ) long double.

    type

    d signed int.i d.o .

    u unsigned unt. x .

    X x .f [-]m.n, m

    , n .e [-]m.n e [+/-]d.

    e .g f e ( )E e, E .G f E.c ( char ).s .p .

    84

  • 7/22/2019 Cibernetica si Informatica Economica (Laborator cu exemple)

    83/83

    B I B L I O G R A F I E

    1. Dr. Kris Jamsa, Lars Klander. Totul despre C i C++. Manual fundamentalde programare n C i C++. Bucureti: Teora, 2000.

    2. Herbert Shildt. C manual complet. Editura Teora, Bucureti, 1998.3. Liviu Negrescu. Limbajele C i C++ pentru nceptori. V. 1. Editura

    Microinformatica, Cluj-Napoca, 1995.4. Vasile Petrovici, Florin Goicea. Programarea n limbajul C. Editura Tehnic,

    Bucureti, 1993.5. tefan BERZAN, Rodica BERZAN. Programarea calculatoarelor. Teste,

    probleme, coduri C pentru lucrrile practice i de laborator. Editura ASEM,Chiinu, 2003.

    6. . . : , 2002.

    7. tefan BERZAN, Rodica BERZAN. . T, , . Editura ASEM, Chiinu,2003.

    8. .. /++ . .: -, 2001.9. . ++.10. Arnush Craig. Borland C++. Moscova, 1997.11. http://www.brainbench.com12. http://www.cplus.about.com13. http://www.programare.ro14. http://www.specialist.ru15. http://www.ipg.h1.ru16. http://www.citforum.ru