使用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;
}
相关推荐
wenyq72 分钟前
LeetCode 438. Find All Anagrams in a String
算法·leetcode
后台模板学习3 分钟前
Rust vs Python 在用户认证模块中的实现:底层
开发语言·python·rust
LB21123 分钟前
力扣102 198 70 55
数据结构·算法·leetcode
所念皆星海91110 分钟前
Python学习---DAY10函数
开发语言·python·学习
鹿角片ljp28 分钟前
LeetCode 42:接雨水|前后最大值DP
算法·leetcode·动态规划
艾莉丝努力练剑1 小时前
【AI大模型接入SDK】ChatGPT API
网络·c++·人工智能·websocket·网络协议·学习·chatgpt
无小道2 小时前
C/C++——atomic小记
c++·cas·无锁
wuyk5552 小时前
104.C 语言字节对齐:从底层原理到工程实践的完整指南
c语言·开发语言·stm32·单片机·嵌入式硬件
君顾18 小时前
智慧零售实战指南:从技术架构到落地方案全解析
java·开发语言·零售