[C++] 별 찍기
1번
*
**
***
****
*****
#include <iostream>
using namespace std;
int main(void)
{
cout << "1번" << endl;
for (int i = 0; i < 5; i++)
{
for ( int j = 0; j <= i; j++)
{
cout << "*";
}
cout << endl;
}
}
2번
*
**
***
****
*****
#include <iostream>
using namespace std;
int main(void)
{
cout << "2번" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = i; j < 4; j++)
{
cout << " ";
}
for (int k = 0; k <= i; k++)
{
cout << "*";
}
cout << endl;
}
}
3번
*****
****
***
**
*
#include <iostream>
using namespace std;
int main(void)
{
cout << "3번" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 5; j > i; j--)
{
cout << "*";
}
cout << endl;
}
}
4번
*****
****
***
**
*
#include <iostream>
using namespace std;
int main(void)
{
cout << "4번" << endl;
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < i; k++)
{
cout << " ";
}
for (int j = 5; j > i; j--)
{
cout << "*";
}
cout << endl;
}
}
5번
*
***
*****
*******
*********
#include <iostream>
using namespace std;
int main(void)
{
cout << "5번" << endl;
for (int i = 0; i < 5; i++)
{
for (int j = 4 - i; j >= 1; j--)
{
cout << " ";
}
for (int k = 0; k <= i * 2; k++)
{
cout << "*";
}
cout << endl;
}
}
6번
*********
*******
*****
***
*
#include <iostream>
using namespace std;
int main(void)
{
cout << "6번" << endl;
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < i; k++)
{
cout << " ";
}
for (int j = i; j < 9 - i; j++)
{
cout << "*";
}
cout << endl;
}
}
7번
*
***
*****
*******
*********
*******
*****
***
*
#include <iostream>
using namespace std;
int main(void)
{
cout << "7번" << endl;
for (int i = 0; i < 4; i++)
{
for (int j = 4 - i; j >= 1; j--)
{
cout << " ";
}
for (int k = 0; k <= i * 2; k++)
{
cout << "*";
}
cout << endl;
}
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < i; k++)
{
cout << " ";
}
for (int j = i; j < 9 - i; j++)
{
cout << "*";
}
cout << endl;
}
for (int i = 0; i < 9; i++) {
if (i < 5) {
for (int a = i; a < 4; a++)
{
cout << " ";
}
for (int b = 0; b <= i * 2; b++)
{
cout << "*";
}
}
else {
for (int a = 4; a < i; a++)
{
cout << " ";
}
//cout << i;
for (int b = i - 5; b < 12 - i; b++)
{
cout << "*";
}
}
cout << endl;
}
}