๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - ๋ก๋ ๋ง๋ค๊ธฐ ๋ณธ๋ฌธ
๐ฉ๐ป IoT (Embedded)/C++
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - ๋ก๋ ๋ง๋ค๊ธฐ
์ง์ง์ํ์นด 2023. 6. 29. 01:37728x90
๋ฐ์ํ
<๋ณธ ๋ธ๋ก๊ทธ๋ ์ด์ํธ๋ฝ ๊ฒ์์์นด๋ฐ๋ฏธ ๋์ ์ ํ๋ธ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค :-)>
=> C++ Let's Make Games
๐ซง ๋ก๋ 1
// Chapter1_10
#include <iostream>
using namespace std;
int main()
{
// Lotto Program
system("cls");
srand((unsigned int)time(0));
int iLotto[45] = {};
// 1 ~ 45๊น์ง์ ์ซ์๋ฅผ ์ฐจ๋ก๋๋ก ๋ฃ์ด์ค๋ค
for (int i = 0; i < 6; i++) {
cout << (rand() % 45 + 1) << endl;
}
return 0;
}
๐ซง ๋ก๋ 2
// Chapter1_10
#include <iostream>
using namespace std;
int main()
{
// Lotto Program
system("cls");
srand((unsigned int)time(0));
int iLotto[45] = {};
// 1 ~ 45๊น์ง์ ์ซ์๋ฅผ ์ฐจ๋ก๋๋ก ๋ฃ์ด์ค๋ค
for (int i = 0; i < 45; i++) {
iLotto[i] = i + 1;
}
// Swap ์๊ณ ๋ฆฌ์ฆ
/* int iNum1 = 1, iNum2 = 2, iNum3;
iNum3 = iNum1;
iNum1 = iNum2;
iNum2 = iNum3;*/
// shuffle
int iTemp, idx1, idx2;
for (int i = 0; i < 100; i++) {
idx1 = rand() % 45;
idx2 = rand() % 45;
iTemp = iLotto[idx1];
iLotto[idx1] = iLotto[idx2];
iLotto[idx2] = iTemp;
}
for (int i = 0; i < 45; i++) {
cout << iLotto[i] << endl;
}
return 0;
}
728x90
๋ฐ์ํ
'๐ฉโ๐ป IoT (Embedded) > C++' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - ์ผ๊ตฌ ๊ฒ์ (0) | 2023.06.30 |
---|---|
C++ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํค๋ ํ์ผ (0) | 2023.06.29 |
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - ๋ฐฐ์ด (0) | 2023.06.29 |
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - do while (0) | 2023.06.29 |
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - ์์ ๋ฌธ์ (๋ค์ํ๊ฒ ๋ณ ์ฐ๊ธฐ, ๊ตฌ๊ตฌ๋จ) (0) | 2023.06.29 |
Comments