๐ฉ๐ป IoT (Embedded)/C++
[inflearn ๊ฐ์] ๊ธฐ๋ณธ ๋ฌธ๋ฒ - ์์ ๋ฌธ์ (๋ค์ํ๊ฒ ๋ณ ์ฐ๊ธฐ, ๊ตฌ๊ตฌ๋จ)
์ง์ง์ํ์นด
2023. 6. 29. 00:39
728x90
๋ฐ์ํ
<๋ณธ ๋ธ๋ก๊ทธ๋ ์ด์ํธ๋ฝ ๊ฒ์์์นด๋ฐ๋ฏธ ๋์ ์ ํ๋ธ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค :-)>
=> C++ Let's Make Games
๐ซง ๋ณ ์ฐ๊ธฐ
// Chapter1_9
#include <iostream>
using namespace std;
int main()
{
// ๋ณ์ฐ๊ธฐ
for (int i = 0; i < 5; i++) {
for (int j = 0; j < i + 1; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
๐ซง ๊ฑฐ๊พธ๋ก ๋ณ ์ฐ๊ธฐ
// Chapter1_9
#include <iostream>
using namespace std;
int main()
{
// ๊ฑฐ๊พธ๋ก ๋ณ์ฐ๊ธฐ
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5 - i; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
๐ซง ๊ฑฐ๊พธ๋ก ๋ณ ์ฐ๊ธฐ
// Chapter1_9
#include <iostream>
using namespace std;
int main()
{
// ์ผ๊ฐํ ๋ณ ์ฐ๊ธฐ
// ๊ณต๋ฐฑ ๋ณ
//3 1
//2 3
//1 5
//0 7
for (int i = 0; i < 4; i++) {
// ๊ณต๋ฐฑ์ ์ํ ๋ฌธ
for (int j = 0; j < 3 - i; j++) {
cout << " ";
}
// *์ ์ํ ๋ฌธ
for (int j = 0; j < i * 2 + 1; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
๐ซง 2๋จ๋ถํฐ 9๋จ ๊ตฌ๊ตฌ๋จ ํ๊ธฐ
// Chapter1_9
#include <iostream>
using namespace std;
int main()
{
// 2๋จ๋ถํฐ 9๋จ๊น์ง ๊ตฌ๊ตฌ๋จ
for (int i = 2; i < 10; i++) {
cout << i << "๊ตฌ๊ตฌ๋จ" << endl;
for (int j = 1; j < 10; j++) {
cout << i << " * " << j << " = " << (i * j) << endl;
}
}
return 0;
}
๐ซง ๋ค์ด์๋ชฌ๋๋ก ๋ณ ์ฐ๊ธฐ
// Chapter1_9
#include <iostream>
using namespace std;
int main()
{
// ๋ค์ด์๋ชฌ๋๋ก ๋ณ ์ฐ๊ธฐ
int iLine = 7;
int iCnt = 0;
for (int i = 0; i < iLine; i++) {
// ๊ณต๋ฐฑ : 3 2 1 0 1 2 3
// ๋ณ : 1 3 5 7 5 3 1
iCnt = i;
// i๊ฐ์ด 4, 5, 6 ์ผ๋๋ง ๋ค์ด๊ฐ
if (i > iLine / 2) {
iCnt = iLine - 1 - i;
}
// i๊ฐ์ด 0, 1, 2, 3 ์ผ๋๋ ๊ทธ๋๋ก iCnt ๋์
// i๊ฐ์ด 4, 5, 6 ์ผ๋๋ iCnt 2, 1, 0 ๋์
// ์ฆ, i๋ 0, 1, 2, 3, 2, 1, 0
for (int j = 0; j < 3 - iCnt; j++) {
cout << " ";
}
for (int j = 0; j < iCnt * 2 + 1; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
728x90
๋ฐ์ํ