10 Oct 2019

  • October 10, 2019
  • Amitraj
Program to print Heart pattern-


Have you tried generating different patterns in C or C++ ?
I know its easy but I am sharing what I tried.

Here is simple Heart pattern.
And will look something like this :




//Program to print heart pattern
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
 clrscr();
 int n,i,j;
 cout<<"Enter limit for pattern : ";
 cin>>n;
 if(n%2==0)
  n++;

 for(i=0;i<n;i++)
 {
  for(j=0;j<n;j++)
  {
   if(i==0&&(j>=n/5&&j<=n/2-n/5)||i==0&&(j>=n/2+n/5&&j<=(n-1)-n/5))
    cout<<"* ";
   else if(i>0&&i<=n/5&&(j==n/5-i||j==n/2+n/5-i||j==n/2-n/5+i||j==(n-1)-n/5+i))
    cout<<"* ";
   else if((i>n/5&&i<=n/2)&&(j==0||j==n-1))
    cout<<"* ";
   else if(i>n/2&&(j==i-n/2||j==(n-1)-(i-n/2)))
    cout<<"* ";
   else
    cout<<"  ";
  }
  cout<<"\n";
 }
 getch();
}


Related Posts:

  • Program to print Heart pattern Program to print Heart pattern- Have you tried generating different patterns in C or C++ ? I know its easy but I am sharing what I tried. Here is simple Heart pattern. And will look something like this : //Program t… Read More
  • C program to ring a bell C program to ring a bell:- #include<stdio.h> int main() {   //following printf will ring a beep sound 3 times.   printf("\a \a \a");               //Note: Here \a sta… Read More
  • Happy Birthday sound in C Happy Birthday sound in C:- #include<dos.h> #include<stdio.h> int main(void) { float g3=195,a3=220,c4=263,b3=247,d4=293,g4=393,e4=330,f4=351; sound(g3); delay(100); nosound(); sound(g3); delay(500); nosoun… Read More
  • Program of System Date and Time Program of System Date and Time:- #include <stdio.h> #include <time.h> int main() {    time_t t;    time(&t);       printf("System date and time is… Read More
  • Graphic program to design a moving car Graphic program to design a moving car:-                             #include<stdio.h> #include<conio.h> #include<graphics.h… Read More

Translate

Popular Posts