Print Heart in C++

Here is the Code of How to Print a Heart Shape in C++ using Heart Character (ascii code 3 = ♥)

Code:

#include<iostream>
using namespace std;
int main()
{
	int i,j,k,n;
	xyz:
	cout<<"enter number greater then 5 \t";
	cin>>n;
	cout<<endl<<endl;
	if(n>=5)
	{
	for(i=3;i<=n;i++)
	{
		for(j=n;j>=i;j--)
			cout<<" ";
		for(k=1;k<=(2*i-1);k++)
			cout<<char(3);
		for(j=2*n;j>=(2*i+1);j--)
			cout<<" ";
		cout<<" ";
		for(k=1;k<=(2*i-1);k++)
			cout<<char(3);
		cout<<endl;
	}
	for(i=(2*n-1);i>=1;i--)
	{
	       for(j=i;j<=2*n;j++)
			cout<<" ";
		for(k=1;k<=(2*i-1);k++)
		    cout<<char(3);
		cout<<endl;
	}
}
else
goto xyz;
}

Output:

enter number greater then 5     7


     ♥♥♥♥♥         ♥♥♥♥♥
    ♥♥♥♥♥♥♥       ♥♥♥♥♥♥♥
   ♥♥♥♥♥♥♥♥♥     ♥♥♥♥♥♥♥♥♥
  ♥♥♥♥♥♥♥♥♥♥♥   ♥♥♥♥♥♥♥♥♥♥♥
 ♥♥♥♥♥♥♥♥♥♥♥♥♥ ♥♥♥♥♥♥♥♥♥♥♥♥♥
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
       ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
        ♥♥♥♥♥♥♥♥♥♥♥♥♥
         ♥♥♥♥♥♥♥♥♥♥♥
          ♥♥♥♥♥♥♥♥♥
           ♥♥♥♥♥♥♥
            ♥♥♥♥♥
             ♥♥♥
              ♥

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *