• 欢迎光临~

【C语言】用"I love you!"打印心形

开发技术 开发技术 2022-10-09 次浏览
#include<iostream>
#include<cmath>
using namespace std;
int main()
{

    float x, y;
    string s = "I love you!";
    int l = s.length();
    for (y = 1.3f; y >= -1.1f; y -= 0.06f)
    {
        int t = 0;
        for (x = -1.1f; x <= 1.1f; x += 0.025f)
        {
            double heart = x * x + (5.0 * y / 4.0 - sqrt(abs(x))) * (5.0 * y / 4.0 - sqrt(abs(x)));
            if (heart <= 1) {
                cout << s[t];
                t = (t + 1) % l;
            }
            else cout << " ";
        }
        cout << endl;
    }
    return 0;
}
程序员灯塔
转载请注明原文链接:【C语言】用"I love you!"打印心形
喜欢 (0)