用C++输出会跳动的心形
时间: 2024-06-01 08:14:05 浏览: 11
我会用C语言输出一个会跳动的心形:# include <stdio.h>int main ()
{
int i, j;
for (i= 1; i<= 5; i++)
{
for (j= 1; j<= 5; j++)
{
if (i== 3 && j== 3)
printf ("Love");
else
printf (" * ");
}
printf ("\n");
}
return 0;
}
相关问题
使用C++输出一个心形
以下是使用C++输出一个心形的代码,可以在命令行窗口中运行:
```c++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const int size = 30;
const double PI = 3.14159265358979323846;
const char heart = '*';
for (int y = size; y >= -size; --y)
{
for (int x = -size; x <= size; ++x)
{
double fx = x / 20.0;
double fy = y / 20.0;
double f = (pow(fx, 2.0) + pow(fy, 2.0) - 1.0) * pow(fx, 2.0) * pow(fy, 2.0);
if (f <= 0.0)
{
cout << heart;
}
else
{
cout << ' ';
}
}
cout << endl;
}
return 0;
}
```
运行效果如下:
```
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
```
c++输出一个心形
以下是一个简单的 C++ 代码,可以输出一个心形:
```c++
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x, y, size;
const double pi = 3.14159265358979323846;
// 输入心形大小
cout << "请输入心形大小(0 到 1 之间的小数):";
cin >> size;
// 输出心形
for (y = 1.5; y > -1.5; y -= 0.1)
{
for (x = -1.5; x < 1.5; x += 0.05)
{
double a = x * x + y * y - 1;
cout << ((a * a * a - x * x * y * y * y <= 0.0) ? '*' : ' ');
}
cout << endl;
}
return 0;
}
```
这段代码使用了数学公式来计算心形的形状,然后通过双重循环输出心形。用户可以输入一个大小参数,以控制心形的大小。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)