1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cstdlib>
#include <ctime>
 
using namespace std;
 
int arr[10];
 
int main() {
 
    int i = 0;
    srand((unsigned)time(NULL));
    
    while (i < 1000) {
        
        const int num = rand() % 10//배열의 크기는 상수여야 하기 때문에 상수화시킴
 
        arr[num] += 1;
        i++;
    }
 
    for (int i = 0; i < 10; i++) {
        cout << i << ": " << arr[i] << endl;
        
    }
 
    return 0;
}
 
cs

 

반응형

+ Recent posts