C++用"I love you!"列印心形
阿新 • • 發佈:2018-12-20
列印心形圖案(撩妹神技)
廢話不多說,上程式碼(先還是說一句心形圖案的函式——自己百度,這裡只涉及到一種,其實有很多)
#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; }
然後開啟你的控制檯,點選左上角
彈出一個選單點選屬性
然後如下圖
確定後你就可以看到紅心咯!