使用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;
}
相关推荐
JosieBook11 分钟前
【鸿蒙开源】把 Windows 任务栏上的流量表搬到鸿蒙 PC:TrafficMonitor 1.86 的 C++ 内核移植实践
c++·windows·harmonyos
电科_银尘16 分钟前
【大模型算法与工程 39】PPO:策略比率、裁剪目标与训练稳定性
人工智能·算法·机器学习
shehuiyuelaiyuehao1 小时前
算法68,字符串相乘
算法
Huangjin007_1 小时前
【C++ 算法竞赛篇】STL 常用知识点速通指南
c++·算法
geovindu2 小时前
rust: Functional Options Pattern
开发语言·后端·设计模式·rust·函数式选项模式·惯用法型模式
skywalk81633 小时前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)
开发语言·前端·人工智能·lightharness
敲上瘾3 小时前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
驭渊的小故事3 小时前
LeetCode 33:搜索旋转排序数组——从二分查找到旋转数组的区间判定
算法·leetcode·职场和发展
炸膛坦客3 小时前
单片机/C/C++八股:(三十三)取别名
c语言·c++·单片机
听情歌落俗4 小时前
嵌入式学习1-C语言基础语法与STM32实践
c语言·开发语言