Advertisement
pan7nikt

TablicaPrzedzial

Dec 11th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. //50-elementowa tablice wypelnic liczbami lopsowymi z przedzialu podanego przez urzytkownika
  2.  
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <time.h>
  7. using namespace std;
  8.  
  9. int tab[50];
  10. int gen;
  11. int i;
  12. int lmin;
  13. int lmax;
  14. int temp;
  15. int lmod;
  16.  
  17. main()
  18. {
  19.     cout << "podaj najnizsza liczbe przedzialu: ";
  20.     cin >> lmin;
  21.     cout << "podaj najwieksza liczbe przedzialu: ";
  22.     cin >> lmax;
  23.    
  24.     if(lmin>lmax)
  25.     {
  26.         temp = lmin;
  27.         lmin = lmax;
  28.         lmax = temp;
  29.     }
  30.    
  31.     lmod = (lmax-(lmin-1)) + lmin;
  32.    
  33.     //do debugowania
  34.     cout << lmod << endl;
  35.    
  36.     srand(time(NULL));
  37.     for(i=0;i<50;i++)
  38.     {
  39.         tab[i] = rand()%lmod;
  40.     }
  41.    
  42.     for(i=0;i<50;i++)
  43.     {
  44.         cout << i+1 << " liczba to: " << tab[i] << endl;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement