c++输出爱心小程序
#include <iostream>
#include <>
#define y x / 4
#define s (x+1-3*y) / 2
int main() {
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
COORD size = { 300, 300 };
SetConsoleScreenBufferSize(hout, size);
SMALL_RECT rc = { 0,0, 300 - 1, 300 - 1 }; // 重置窗口位置和大小
SetConsoleWindowInfo(hout, true, &rc);
int x;
agin:
std::cout << "请输入最小10,并且以加8递增,最大为106:";
std::cin >> x;
if (x<10||x>106||(x-10)%8!=0)
{
system("cls");
goto agin;
}
int a = 1;
for (int i = 0; i <= x; i++)
{
for (int j = 0; j <= x; j++)
{
if (i < y && !((j >= y - i && j <= y + s - 1 + i) || (j >= 2 * y + s - i && j <= 2 * y + 2 * s + i - 1)))
{
std::cout << " ";
}
else if (i > x - 2 * y && i <= x && !((j >= a && j <= x - a)))
{
std::cout << " ";
}
else
{
std::cout << "★";
}
}
if (i > x - 2 * y && i < x)
{
a++;
}
std::cout << "\n";
}
}