Advertisement
Guest User

Spr_informatyka

a guest
Mar 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11.  
  12.     cout << "ZADANIE 1A" << endl << endl;
  13.  
  14.     int x, y = 0;
  15.  
  16.     cout << "Podaj 2 liczby calkowite: ";
  17.     cin >> a >> b;
  18.  
  19.     switch(a)
  20.     {
  21.     case 12:
  22.         cout << "Podano liczbe 12, a druga liczba to: " << b;
  23.         break;
  24.     case -12:
  25.         cout << "Kwadrat drugiej liczby: " << y * y;
  26.         break;
  27.     case 15:
  28.         cout << "Druga liczba podzielona przez 5: " << (float)y / 5.0;
  29.         break;
  30.     case 22:
  31.         {
  32.             error:
  33.             if(y < 0)
  34.             {
  35.                 cout << "Podaj ponownie 2 liczbe (taka aby byla >= 0): ";
  36.                 cin >> y;
  37.                 goto error;
  38.             }
  39.             cout << "Pierwiastek z drugiej liczby: " << sqrt(y);
  40.             break;
  41.         }
  42.     case -24:
  43.         cout << "Srednia z obu liczb: " << (float)(x + y) / 2.0;
  44.         break;
  45.     default:
  46.         cout << "nieprawidlowy wybor";
  47.     }
  48.  
  49.     cout << endl;
  50.  
  51.  
  52.     cout << endl << "ZADANIE 1B" << endl << endl;
  53.  
  54.     for(int i = 10; i <= 21; i++)
  55.     {
  56.         cout.width( 4 );
  57.         cout << i;
  58.     }
  59.  
  60.     cout << endl << endl;
  61.  
  62.     for(int i = 45; i >= -15; i-=5)
  63.     {
  64.         cout.width( 4 );
  65.         cout << i;
  66.     }
  67.  
  68.     cout << endl << endl;
  69.  
  70.     for(int i = 1; i <= 9; i++)
  71.     {
  72.         for(int a = 1; a <= 11; a++)
  73.         {
  74.             cout.width( 4 );
  75.             cout << a * i;
  76.         }
  77.         cout << endl;
  78.     }
  79.  
  80.     cout << endl << endl;
  81.  
  82.     for(int i = 9; i >= 2; i--)
  83.     {
  84.         for(int a = 7; a >= 2; a--)
  85.         {
  86.             cout.width( 4 );
  87.             cout << a * i;
  88.         }
  89.         cout << endl;
  90.     }
  91.  
  92.     cout << endl << "ZADANIE 2A" << endl << endl;
  93.  
  94.     cout << "Podaj liczbe A (double): ";
  95.     cin >> A;
  96.  
  97.     jeden:
  98.  
  99.     if(A > 0)
  100.     {
  101.         A /= 10;
  102.         if(A < 8)
  103.         {
  104.             A += 12;
  105.             trzy:
  106.             if(A < 50)
  107.             {
  108.                 cout << "Liczba A: " << A << endl;
  109.                 goto koniec;
  110.             }
  111.             else
  112.             {
  113.                 goto jeden;
  114.             }
  115.         }
  116.         else
  117.         {
  118.             A -= 20;
  119.             goto jeden;
  120.         }
  121.     }
  122.     else
  123.     {
  124.         dwa:
  125.         A += 10;
  126.         if(A < 20)
  127.         {
  128.             goto dwa;
  129.         }
  130.         else
  131.         {
  132.             A /= 3;
  133.             goto trzy;
  134.         }
  135.     }
  136.  
  137.     koniec:
  138.    
  139.  
  140.     cout << endl << "ZADANIE 2B" << endl << endl;
  141.  
  142.     srand(time(NULL));
  143.  
  144.     for(int t = 0; t < 10; t++)
  145.     {
  146.         cout << rand() % 10 + 1 << " ";
  147.     }
  148.     cout << endl << endl;
  149.  
  150.     for(int t = 0; t < 10; t++)
  151.     {
  152.         cout << rand() % 501 - 200 << " ";
  153.     }
  154.     cout << endl << endl;
  155.  
  156.     for(int t = 0; t < 10; t++)
  157.     {
  158.         comeback:
  159.         int a = rand() % 101 - 60;
  160.         if (a % 4 == 0)
  161.             cout << a << " ";
  162.         else
  163.             goto comeback;
  164.     }
  165.     cout << endl << endl;
  166.  
  167.     for(int t = 0; t < 10; t++)
  168.     {
  169.         float f = (rand() % 301) / 10.0;
  170.         f -= 15.0;
  171.  
  172.         cout << f << " ";
  173.     }
  174.     cout << endl << endl;
  175.  
  176.     return 0;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement