Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int main() {
  6.  
  7.    int y;
  8.    float x;
  9.  
  10.    printf("Pocatecni hodnota promenne: %d\n", y);
  11.  
  12.    printf("Preteceni integeru:\n");
  13.    y = 0;
  14.    for(int i = 0; i < 10; i++) {
  15.       y += 1000000000;
  16.       printf("%d\n", y);
  17.    }
  18.  
  19.    /////////////////////////////////////////////////////////////////////////////
  20.    ///   Deleni
  21.    /////////////////////////////////////////////////////////////////////////////
  22.    printf("\n\nvysledky deleni\n");
  23.    printf("3.0f/2.0f = %f\n", 3.0f / 2.0f);
  24.    
  25.    y = 10/3;
  26.    printf("int y = 10/3; y = %d\n", y);
  27.  
  28.    x = 10/3;
  29.    printf("float x = 10/3; x =  %f\n", x);
  30.  
  31.    x = 10.0f / 3;
  32.    printf("float x = 10.0f/3; x = %f\n", x);
  33.  
  34.    //nasledujici priklad shodi cely program (proto je zakomentovany)
  35.    int MAM_TAK_CHYTRY_KOMPILATOR_ZE_TO_NEJDE_NAPSAT_ROVNOU = 0;
  36.    y = 10/MAM_TAK_CHYTRY_KOMPILATOR_ZE_TO_NEJDE_NAPSAT_ROVNOU;
  37.    printf("intove deleni nulou: 10/0 = %d\n", y);
  38.    
  39.    float DELENI_FLOATOVOU_NULOU_TO_TAKY_NEVEZME_ROVNOU_I_KDYZ_TO_NORMA_DOVOLUJE = 0.f;
  40.    x = 10.0f / DELENI_FLOATOVOU_NULOU_TO_TAKY_NEVEZME_ROVNOU_I_KDYZ_TO_NORMA_DOVOLUJE;
  41.    printf("floatove deleni nulou: 10.0f/0.f = %f\n", x);
  42.    x = -10.0f / DELENI_FLOATOVOU_NULOU_TO_TAKY_NEVEZME_ROVNOU_I_KDYZ_TO_NORMA_DOVOLUJE;
  43.    printf("floatove deleni nulou: -10.0f/0.f = %f\n", x);
  44.    x = DELENI_FLOATOVOU_NULOU_TO_TAKY_NEVEZME_ROVNOU_I_KDYZ_TO_NORMA_DOVOLUJE/DELENI_FLOATOVOU_NULOU_TO_TAKY_NEVEZME_ROVNOU_I_KDYZ_TO_NORMA_DOVOLUJE;
  45.    printf("0f/0.f = %f\n", x);
  46.  
  47.  
  48.    /////////////////////////////////////////////////////////////////////////////
  49.    ///   Presnost
  50.    /////////////////////////////////////////////////////////////////////////////
  51.    x = 1.23456789123456789f;
  52.    printf("\n\nOmezena presnost floatu: 1.23456789123456789f = %f\n", x);
  53.    x = 0.7f;
  54.    x *= 1024.0f;
  55.    printf("Omezena presnost floatu: 0.7f*1024.0f = %f\n", x);
  56.  
  57.  
  58.    x = cos(1.0f)*cos(1.0f)+sin(1.0f)*sin(1.0f);
  59.    printf("cos(1.0f)*cos(1.0f)+sin(1.0f)*sin(1.0f) = %f, a toto cislo se ", x);
  60.    if(x == 1.0f) {
  61.       printf("rovna");
  62.    } else {
  63.       printf("nerovna");
  64.    }
  65.    printf(" %f\n", 1.0f);
  66.  
  67.    printf("Pokud pouzijeme porovnani s epsilonem: %f ", x);
  68.    if(abs(x-1.0f) < 0.00001) {
  69.       printf("==");
  70.    } else {
  71.       printf("!=");
  72.    }
  73.    printf(" %f.\n", 1.0f);
  74.  
  75.    system("PAUSE");
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement