grodek118

Losowanie z podawanego przedzialu

Aug 12th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int wylosuj(int a, int b)
  9. {
  10. int wynik = (rand() % b) + a;
  11. return wynik;
  12. }
  13.  
  14. int main()
  15. {
  16. cout << "Podaj liczby tworzace przedzial" << endl;
  17. srand( time( NULL ) );
  18. int start;
  19. cin >> start;
  20. int stop;
  21. cin >> stop;
  22. int ile = 20;
  23. do
  24. {
  25. cout << wylosuj( start, stop ) << endl;
  26. ile--;
  27. } while( ile > 0 );
  28.  
  29. return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment