gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
program do prints heart with c++
- User
program do prints heart with c++
- Assistant
Here is a C++ program to print a heart shape:
#include <iostream> using namespace std; int main() { int width = 16; int height = 10; for (int y = height / 2; y <= height; y += 2) { for (int x = 1; x < width - y / 2; x += 2) { cout << " "; } for (int x = 1; x <= y; x++) { cout << "*"; } for (int x = 1; x <= width - y; x++) { cout << " "; } for (int x = 1; x <= y; x++) { cout << "*"; } cout << endl; } for (int y = height; y >= 1; y -= 2) { for (int x = 1; x <= width - y / 2; x += 2) { cout << " "; } for (int x = 1; x <= y; x++) { cout << "*"; } for (int x = 1; x <= width - y; x++) { cout << " "; } for (int x = 1; x <= y; x++) { cout << "*"; } cout << endl; } return 0; }This program will print a heart shape using asterisks (*). The size of the heart is determined by the
widthandheightvariables. You can adjust these variables to change the size of the heart.