Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int x[20000], i;
  10.     int contadores[101];
  11.  
  12.     for (i=0; i<101; i++)
  13.         contadores[i] = 0;
  14.  
  15.     srand( time(0) );
  16.  
  17.     for (i=0; i<20000; i++)
  18.     {
  19.         x[i] = rand() % 101;
  20.         contadores[x[i]]++;
  21.     }
  22.  
  23.     for (i=0; i<101; i++)
  24.         cout << "Frequencia de " << i << ": " << contadores[i] << endl;
  25.  
  26.     cout << "Agora, calculemos a media." << endl;
  27.  
  28.     int soma = 0;
  29.     for (i=0; i<20000; i++)
  30.         soma = soma + x[i];
  31.     cout << "A media eh: " << soma/20000.0 << endl;
  32.  
  33.  
  34.     int menorFreq = contadores[0];
  35.     int oCaraDeMenorFreq = 0;
  36.     for (i=0; i<101; i++)
  37.     {
  38.         if (contadores[i] < menorFreq)
  39.         {
  40.             menorFreq = contadores[i];
  41.             oCaraDeMenorFreq = i;
  42.         }
  43.     }
  44.     cout << "Menor freq.: " << menorFreq << endl;
  45.     cout << "Numero com menor freq.: " << oCaraDeMenorFreq << endl;
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement