C++输出爱心

发布于 2021-11-03  989 次阅读


最近在CSDN上找到了一个有意思的代码哈哈哈,输出爱心

然后用cmd命令修改一下颜色就很舒服,代码贴下面了

#include<iostream>
#include<cmath>
#include<stdlib.h>
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 << " ";
            }
			system("color 7c");
            cout << endl;
        }
			system("pause");
    return 0;
}

执行效果如下

system("pause")是为了暂停,color是改变控制台颜色

届ける言葉を今は育ててる
最后更新于 2021-11-09