做一个爱心的c++程序
时间: 2023-06-19 12:05:15 浏览: 62
以下是一个简单的爱心 C++ 程序:
```c++
#include <iostream>
using namespace std;
int main() {
cout << " ** ** " << endl;
cout << " **** **** " << endl;
cout << " ****** ****** " << endl;
cout << " ****** ****** " << endl;
cout << " **** **** " << endl;
cout << " ** ** " << endl;
cout << " ** ** " << endl;
cout << " **** " << endl;
cout << " ** " << endl;
return 0;
}
```
这个程序输出了一个简单的 ASCII 爱心图案。你可以在控制台中运行它,看到输出的效果。
相关问题
c++ 写一个爱心程序
以下是一个简单的爱心程序:
```
#include <stdio.h>
int main()
{
int i, j;
for (i = -10; i <= 10; i++)
{
for (j = -10; j <= 10; j++)
{
if ((i * i + j * j - 15) * (i * i + j * j - 15) * (i * i + j * j - 15) - i * i * j * j * j <= 0)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
```
该程序使用嵌套循环和数学公式来绘制一个简单的爱心图案。如果您想要更复杂的图案,可以尝试使用其他算法和工具来制作。
用C++ 写一个爱心程序
以下是一个简单的用C++实现的爱心程序,它将在控制台中输出一个爱心图案:
```c++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int width = 40;
const int height = 20;
char heart[height][width];
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
float dist = sqrt(pow((float)x - width / 2, 2) + pow((float)y - height / 2, 2));
if (dist <= height / 2)
{
float angle = atan2((float)y - height / 2, (float)x - width / 2);
float heart = sin(angle * 3);
if (heart < 0)
{
cout << " ";
}
else
{
cout << "*";
}
}
else
{
cout << " ";
}
}
cout << endl;
}
return 0;
}
```
运行该程序,将会输出如下的爱心图案:
```
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
```