728x90
#include <iostream>
#include <time.h>
using namespace std;
int main() {
srand((unsigned int)time(0));
int Lotto[45] = {};
for (int i = 0; i < 45; ++i) {
Lotto[i] = i + 1;
}
int itemp, index1, index2; //Lotto 배열의 인덱스처럼 사용할 변수 선언
for (int i = 0; i < 100; ++i) {
index1 = rand() % 45;
index2 = rand() % 45;
itemp = Lotto[index1];
Lotto[index1]= Lotto[index2];
Lotto[index2]= itemp;
}
for (int i = 0; i < 6;++i){
cout << Lotto[i] << "\t";
}
cout << "보너스번호: " << Lotto[6] << endl;
return 0;
}
728x90
'C++ > c++' 카테고리의 다른 글
[c++] std::array / try catch / auto element 연습 예제 (0) | 2021.09.21 |
---|---|
[c++] 코딩테스트에서 ios::sync_with_stdio; cin.tie(0); 를 쓰면 좋은 이유 (0) | 2021.09.19 |
[c++] 공백을 포함한 문자열을 입력하기 좋은 함수 getline() (0) | 2021.09.19 |
c++ 특정 함수의 인자로 배열주소를 넘기면? (0) | 2021.09.19 |
#include <conio.h> _getch() 설명과 코드 예시 (0) | 2021.05.25 |