Advertisement
Kacper_Michalak

Zadania losowanie wszystko

Feb 15th, 2021
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. // Zadanie 1
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int i;
  10.     srand(time(NULL));
  11.     for (i = 0; i < 3; i++)
  12.     {
  13.         cout << rand() % (9 + 1) << endl;
  14.     }
  15. }
  16.  
  17. // Zadanie 2
  18. #include <iostream>
  19. #include <cstdlib>
  20. #include <ctime>
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25.     int i;
  26.     int a = 30;
  27.     int b = 40;
  28.     srand(time(NULL));
  29.     for (i = 0; i < 5; i++)
  30.     {
  31.         cout << a + rand() % (b - a + 1) << " ";
  32.     }
  33. }
  34. // Zadanie 3
  35. #include <iostream>
  36. #include <cstdlib>
  37. #include <ctime>
  38. using namespace std;
  39.  
  40. int main()
  41. {
  42.     int i;
  43.     int a = 10;
  44.     int b = 20;
  45.     int suma = 0;
  46.     int x;
  47.     srand(time(NULL));
  48.     for (i = 0; i < 100; i++)
  49.     {
  50.         x = a + rand() % (b - a + 1);
  51.         suma = suma + x;
  52.     }
  53.     cout << suma << endl;
  54. }
  55. // Zadanie 4
  56. #include <iostream>
  57. #include <cstdlib>
  58. #include <ctime>
  59. using namespace std;
  60.  
  61. int main()
  62. {
  63.     int i;
  64.     int x;
  65.     srand(time(NULL));
  66.  
  67.     x = rand() % (1 + 1);
  68.     if (x == 0)
  69.     {
  70.         cout << "Orzel" << endl;
  71.     }
  72.     else
  73.         cout << "Reszka" << endl;
  74.  
  75.     /* Wyniki są losowe */
  76. }
  77. // Zadanie 5
  78. #include <iostream>
  79. #include <cstdlib>
  80. #include <ctime>
  81. using namespace std;
  82.  
  83. int main()
  84. {
  85.     int i;
  86.     int x;
  87.     int a=-1000;
  88.     int b=1000;
  89.     srand(time(NULL));
  90.  
  91.     do
  92.     {
  93.         x = a + rand() % (b - a + 1);
  94.         cout << x << endl;
  95.     } while (x <=100 || x >= 200);
  96.    
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement