FilipKinderman

Losowość - zadania

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