๐Ÿ‘ฉ‍๐Ÿ’ป 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
๋ฐ˜์‘ํ˜•