Program to Print Love Heart Star Pattern
Program to Print Love Heart Star Pattern in C Programming:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,size;
printf("\n How many lines or size of heart:- ");
scanf("%d",&size);
printf("\n");
for(i=size/2;i<=size;i+=2)
{
for(j=1;j<size-i;j+=2)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
for(j=1;j<=size-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=size;i>=1;i--)
{
for(j=i;j<size;j++)
{
printf(" ");
}
for(j=1;j<=(i*2)-1;j++)
{
printf("*");
}
printf("\n");
}
}
#include<conio.h>
void main()
{
int i,j,size;
printf("\n How many lines or size of heart:- ");
scanf("%d",&size);
printf("\n");
for(i=size/2;i<=size;i+=2)
{
for(j=1;j<size-i;j+=2)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
for(j=1;j<=size-i;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=size;i>=1;i--)
{
for(j=i;j<size;j++)
{
printf(" ");
}
for(j=1;j<=(i*2)-1;j++)
{
printf("*");
}
printf("\n");
}
}
- This program prompts the user to enter the value of n, which represents the height of the heart shape.
- The heart is divided into two parts: the upper part and the lower part.
- The upper part consists of two triangular sections
- The lower part is a rectangular section.
-
The program uses nested loops and conditional statements to determine
whether to print a star (*) or a space.