rikardoricz

Tomasz Świątek 3BTI los

Feb 9th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. //zad1
  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()% 10 <<endl;
  15.     }
  16.     return 0;
  17. }
  18.  
  19. //zad2
  20.  
  21. #include <iostream>
  22. #include <cstdlib>
  23. #include <ctime>
  24.  
  25. using namespace std;
  26.  
  27. int main()
  28. {
  29.     int a,b;
  30.     a=30;
  31.     b=40;
  32.  
  33.     srand (time (NULL));
  34.  
  35.     cout << a+rand()%(b-a+1) << " ";
  36.     cout << a+rand()%(b-a+1) << " ";
  37.     cout << a+rand()%(b-a+1) << " ";
  38.     cout << a+rand()%(b-a+1) << " ";
  39.     cout << a+rand()%(b-a+1) << " ";
  40.  
  41.     return 0;
  42. }
  43.  
  44.  
  45. //zad3
  46.  
  47. #include <iostream>
  48. #include <cstdlib>
  49. #include <ctime>
  50.  
  51. using namespace std;
  52.  
  53. int main()
  54. {
  55.     srand (time (NULL));
  56.     int s=0;
  57.     for (int i=0;i<100;i++)
  58.     {
  59.         int randInt = rand() % (20-10+1)+10;
  60.         s=s+randInt;
  61.     }
  62.     cout << s << endl;
  63.     return 0;
  64. }
  65.  
  66. //zad4
  67.  
  68. #include <iostream>
  69. #include <cstdlib>
  70. #include <ctime>
  71.  
  72. using namespace std;
  73.  
  74. int main()
  75. {
  76.     srand(time(NULL));
  77.     int x;
  78.     cout << "Podaj ile razy rzucic moneta: ";
  79.     cin >> x;
  80.  
  81.     int i=0;
  82.     while(i < x)
  83.     {
  84.     int rzut = rand() %2;
  85.     cout << rzut;
  86.     if(rzut == 0)
  87.     {
  88.         cout << " - orzel" << endl;
  89.         i++;
  90.     }
  91.     else
  92.     {
  93.         cout << " - reszka" << endl;
  94.         i++;
  95.     }
  96.     }
  97.     //albo mamy 0 albo 1, jest to w sumie losowe, a nie zawsze pokazuje sie to samo.
  98.     return 0;
  99. }
  100.  
  101. //zad5
  102.  
  103. #include <iostream>
  104. #include <cstdlib>
  105. #include <ctime>
  106.  
  107. using namespace std;
  108.  
  109. int main()
  110. {
  111.     srand(time(NULL));
  112.     int x;
  113.     do
  114.     {
  115.         x = -1000+rand()%2001;
  116.         cout<< x <<endl;
  117.     }
  118.     while (x<100 || x>200);
  119.  
  120.     cout << "Liczba przy ktorej zatrzymal sie program: " << x;
  121.  
  122.     return 0;
  123. }
  124.  
Advertisement
Add Comment
Please, Sign In to add comment