C program to print heart star pattern

  • Write a program in C to print a heart shape star pattern.
  • How to draw a Heart on screen using star characters in C.
Heart star pattern program's output should be:
 **   **
**** ****
*********
 *******
  *****
   ***
    *

Required Knowledge

C program to print Heart star pattern on screen

#include <stdio.h>  
  
int main() {  
    int i,j, rows;
    
    printf("Enter the number of rows\n");
    scanf("%d", &rows);  
    /* printing top semi circular shapes of heart */
    for(i = rows/2; i <= rows; i+=2){ 
     /* Printing Spaces */ 
        for(j = 1; j < rows-i; j+=2) {  
            printf(" ");  
        }
        /* printing stars for left semi circle */
        for(j = 1; j <= i; j++){  
            printf("*");  
        }  
        /* Printing Spaces */ 
        for(j = 1; j <= rows-i; j++){  
            printf(" ");  
        }  
        /* printing stars for right semi circle */
        for(j = 1; j <= i; j++){  
            printf("*");  
        }  
        /* move to next row */
        printf("\n");  
    }  
    
    /* printing inverted start pyramid */
    for(i = rows; i >= 1; i--){  
        for(j = i; j < rows; j++){  
            printf(" ");  
        }  
        for(j = 1; j <= (i*2)-1; j++){  
            printf("*");  
        }  
        /* move to next row */
        printf("\n");  
    }  
  
    return 0;  
}  
Output
Enter the number of rows
7
 **   **
**** ****
*********
 *******
  *****
   ***
    *

Related Topics
C program hut star pattern
C program diamond star pattern
C program rhombus star pattern
C program hollow pyramid star pattern
C program binary rectangle pattern
C program multiplication table triangle pattern
C program prime number triangle pattern
C program palindrome triangle pattern
C program diamond star pattern
List of all C pattern programs