使用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;
}
相关推荐
半桶水专家6 小时前
go语言中的结构体嵌入详解
开发语言·后端·golang
长安er6 小时前
LeetCode215/347/295 堆相关理论与题目
java·数据结构·算法·leetcode·
元亓亓亓6 小时前
LeetCode热题100--62. 不同路径--中等
算法·leetcode·职场和发展
在屏幕前出油6 小时前
二、Python面向对象编程基础——理解self
开发语言·python
小白菜又菜7 小时前
Leetcode 1925. Count Square Sum Triples
算法·leetcode
粉红色回忆7 小时前
用链表实现了简单版本的malloc/free函数
数据结构·c++
阿方索7 小时前
python文件与数据格式化
开发语言·python
登山人在路上8 小时前
Nginx三种会话保持算法对比
算法·哈希算法·散列表
写代码的小球8 小时前
C++计算器(学生版)
c++·算法
AI科技星8 小时前
张祥前统一场论宇宙大统一方程的求导验证
服务器·人工智能·科技·线性代数·算法·生活