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 |
반응형
'프로그래밍 언어 > C++' 카테고리의 다른 글
(C++) 함수 오버로딩 & 디폴트 매개변수 (0) | 2021.09.14 |
---|---|
(C++) 이차원 배열 출력 (0) | 2021.09.14 |
(C++) 문자 & 문자열 입력 및 추출 (0) | 2021.09.14 |