Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- void fillRandom(int arr[], int len){
- for(int i=0; i<len; i++) arr[i]=10+(rand()%11);
- }
- void calculateDistribution(const int arr[], int len, double dist[]){
- for(int i=0; i<11; i++) dist[i]=0.0;
- for(int i=0; i<len; i++) dist[arr[i]-10]+=1.0;
- for(int i=0; i<11; i++) dist[i]/=(double)len*0.01;
- }
- void printDistribution(const double dist[]){
- cout<<"Az elofordulasi gyakorisagok:"<<endl<<endl;
- for(int i=0; i<11; i++) cout<<i+10<<": "<<dist[i]<<" %"<<endl;
- }
- int main(){
- srand(time(NULL));
- int arr[100];
- fillRandom(arr,100);
- double dist[11];
- calculateDistribution(arr,100,dist);
- printDistribution(dist);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement