c++心型代码
时间: 2023-07-09 22:12:29 浏览: 41
以下是一个简单的 C++ 心型代码:
```c++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x, y, size;
double pi = 3.14159265358979323846;
int points = 100;
cout << "Enter the size of the heart: ";
cin >> size;
for (int i = 0; i < points; i++)
{
double t = i * 2.0 * pi / points;
x = size * 16 * pow(sin(t), 3);
y = -size * (13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t));
for (int j = 0; j < x + size * 16; j++)
cout << " ";
cout << "X" << endl;
if (i == points / 2)
cout << "Happy Valentine's Day!" << endl;
}
return 0;
}
```
这个程序可以根据用户输入的大小绘制一个心形,并输出一条祝福语。