Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. void fillRandom(int arr[], int len){
  8.     for(int i=0; i<len; i++) arr[i]=10+(rand()%11);
  9. }
  10.  
  11. void calculateDistribution(const int arr[], int len, double dist[]){
  12.     for(int i=0; i<11; i++) dist[i]=0.0;
  13.     for(int i=0; i<len; i++) dist[arr[i]-10]+=1.0;
  14.     for(int i=0; i<11; i++) dist[i]/=(double)len*0.01;
  15. }
  16.  
  17. void printDistribution(const double dist[]){
  18.     cout<<"Az elofordulasi gyakorisagok:"<<endl<<endl;
  19.     for(int i=0; i<11; i++) cout<<i+10<<": "<<dist[i]<<" %"<<endl;
  20. }
  21.  
  22. int main(){
  23.     srand(time(NULL));
  24.     int arr[100];
  25.     fillRandom(arr,100);
  26.     double dist[11];
  27.     calculateDistribution(arr,100,dist);
  28.     printDistribution(dist);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement