爱心~~~红色的~~~小爱心组成的大爱心~~~

哈哈哈哈哈哈哈,小爱心的发现是个意外意外意外

咳咳,正题

今天本来是在LeetCode上刷题,想到了异或操作,之前没有试过字符与字符的异或,于是试了一下

#include <iostream>
using namespace std;
int main()
{
	char ans;
	ans = 'a' ^ 'b';
	cout << ans;
	std::system("pause");
	return 0;
}

然后

结果让我很激动!!!
在这里插入图片描述
竟然是个小爱心!!!
想到网上很多心形的代码组成元素基本是是*#$&等等这些元素,就想试一下,用小爱心组成的大爱心~~~

于是

#include <iostream>
#include "windows.h"
#include<cmath>
using namespace std;
void heartShaped()
{
	float x, y;
	char heart;
	heart = 'a' ^ 'b';
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);  // 设置颜色输出为红色~~~
	for (y = 1.5f; y > -1.5f; y -= 0.1f)
	{
		for (x = -1.5f; x < 1.5f; x += 0.05f)
		{
			float a = x * x + y * y - 1;
			if ((a * a * a - x * x * y * y * y) <= 0)//心形方程
				cout <<heart;
			else cout << " ";
		}
		cout << endl;
	}
	
}

int main()
{
	
	heartShaped();
	
	std::system("pause");
	return 0;
}

Ctrl+F5

叮当~~~~
在这里插入图片描述

发布了96 篇原创文章 · 获赞 19 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Thera_qing/article/details/103366949