Advertisement
bartkoo

rand

Feb 12th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. void zad_1();
  8. void zad_2();
  9. void zad_3();
  10. void zad_4();
  11. void zad_5();
  12.  
  13. int main()
  14. {
  15.     srand(time(NULL));
  16.     cout<<"Zadanie 1"<<endl;
  17.     zad_1();
  18.     cout<<endl;
  19.     cout<<"Zadanie 2"<<endl;
  20.     zad_2();
  21.     cout<<endl;
  22.     cout<<"Zadanie 3"<<endl;
  23.     zad_3();
  24.     cout<<endl;
  25.     cout<<"Zadanie 4"<<endl;
  26.     zad_4();
  27.     cout<<endl;
  28.     cout<<"Zadanie 5"<<endl;
  29.     zad_5();
  30.     cout<<endl;
  31.     return 0;
  32. }
  33.  
  34. void zad_1(){
  35.     for(int i=0; i<3; i++) cout<<rand()%10<<endl;
  36. }
  37.  
  38. void zad_2(){
  39.     for(int i=0; i<5; i++) cout<<30+rand()%(11)<<endl;
  40. }
  41.  
  42. void zad_3(){
  43.     int sum = 0;
  44.     for(int i=0; i<100; i++) sum += 10+rand()%(11);
  45.     cout<<sum<<endl;
  46. }
  47.  
  48. void zad_4(){
  49.     for(int i=0; i<10; i++) cout<<rand()%2<<endl;
  50.     //zdaje sie ze sa losowe (0 [reszka] oraz 1 [orzel])
  51. }
  52.  
  53. void zad_5(){
  54.     int ran;
  55.     do{
  56.         ran = -1000 + rand()%2001;
  57.         cout<<ran<<endl;
  58.     }while(!((ran >= 100) && (ran <= 200)));
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement