Advertisement
pan7nikt

zliczanieTabWszystkie

Jan 28th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. int tab[200];
  7. int ilosc[20];
  8. int i;
  9. int a;
  10. int l;
  11.  
  12. main()
  13. {
  14.     srand(time(NULL));
  15.    
  16.     for(i=0; i<200; i++)
  17.     {
  18.         tab[i] = rand()%21 - 10;
  19.         cout << tab[i] << "." << endl;
  20.         a = -10;
  21.        
  22.         while(a <= 10)
  23.         {
  24.             if(tab[i] == a)
  25.             {
  26.                 ilosc[a+10] = ilosc[a+10] + 1;
  27.                 break;
  28.             }
  29.             else
  30.             {
  31.                 a++;
  32.             }
  33.         }
  34.     }
  35.    
  36.     l = -10;
  37.    
  38.     for (i=0; i<20; i++)
  39.     {
  40.         cout << "liczba " << l << " wystapila " << ilosc[i] << " razy" << endl;
  41.         l++;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement