使用c++实现输出爱心(软件:visual Studio)

cs 复制代码
#include <iostream>
using namespace std;

int main()
{
    //爱心曲线方程(x^2+y^2-a)^3-x^2*y3=0
    double a = 0.5;
    //定义绘图边界
    double bound = 1.3 * sqrt(a);
    //x,y坐标变化步长
    double step = 0.05;

    //二维扫描所有点,外层逐层扫描
    for (double y = bound; y >= -bound; y -= step)
    {
        //内层逐点扫描
        for (double x = -bound; x <= bound; x += 0.5 * step)
        {
            double result = pow( (pow(x, 2) + pow(y, 2)-a), 3) - pow(x, 2) * pow(y, 3);
            if (result <= 0)
                cout << "*";
            else
                cout << " ";
        }
        cout << endl;
    }
    cin.get();

    return 0;
}
相关推荐
玖玥拾5 分钟前
LeetCode 125 验证回文串
算法·leetcode
「QT(C++)开发工程师」5 小时前
C++ 11 常用for循环
开发语言·c++
我还记得那天6 小时前
0 初识C++
开发语言·c++
FfHUCisI6 小时前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI6 小时前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
Asize7 小时前
146. LRU 缓存
算法
Asize7 小时前
543. 二叉树的直径
算法
lemon_sjdk7 小时前
ObjectProperty
java·开发语言·算法
大模型码小白7 小时前
Spring AI Tool 实现自然语言操作 MySQL 数据库详解
服务器·开发语言·数据库·人工智能·python·mysql·spring